mercredi 31 octobre 2018

android:gravity="center" is not working in Pre-Lollipop Android?

I have made an Android Application and I know that Pre-Lollipop devices are negligible as compared to post-lollipop devices.

I recently ran my app on Emulator and found out that the text is not aligned to center when the gravity = "center". You can see the Image attachedenter image description here

The Text Sync and the icon is not at the center but on post lollipop devices they are at the center. The xml code for the above case is :

<RelativeLayout
                        android:id="@+id/sync_layout"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="10dp"
                        android:layout_alignBottom="@+id/contacts"
                        android:layout_alignTop="@+id/contacts"
                        android:layout_alignParentRight="true">


                        <ImageView
                            android:id="@+id/sync_contacts"
                            android:layout_width="24dp"
                            android:layout_height="24dp"
                            android:layout_centerVertical="true"
                            android:background="@drawable/ripplebg_viewscircle"
                            android:padding="5dp"
                            android:rotation="0"
                            app:srcCompat="@drawable/kj_sync" />


                        <ProgressBar
                            android:id="@+id/sync_progress_bar"
                            android:layout_width="24dp"
                            android:layout_height="24dp"
                            android:layout_centerVertical="true"
                            android:visibility="gone" />

                    </RelativeLayout>

                    <TextView

                        android:id="@+id/sync_text"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_toLeftOf="@+id/sync_layout"
                        android:layout_alignTop="@+id/sync_layout"
                        android:layout_alignBottom="@+id/sync_layout"
                        android:text="Sync"
                        android:gravity="center"
                        android:paddingLeft="5dp"
                        android:paddingRight="5dp"
                        android:textColor="#4A4A4A"
                        />

Can you tell me why this is happening and the remedy for this?

Aucun commentaire:

Enregistrer un commentaire