in Android's RelativeLayout we can set textView exact in the center of the screen with this code:
<TextView
android:text="This is TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
result:
top
-
-
-
-
This is TextView (center vertical)
-
-
-
-
bottom
But I need the textView to be a little bit to the bottom, I try add marginTop
but seems like after using layout_centerVertical=true
its become impossible. Any solution?
Expected result (a little bit to bottom):
top
-
-
-
-
-
-
This is TextView (center vertical slight to bottom)
-
-
bottom
Try this:
Try to use RelativeLayout which can easily done your requirement using weight :
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical">
<TextView
android:id="@id/dummy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_below="@id/dummy"
android:layout_marginTop="10dp"
android:text="This is TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
Why should add nested view inside parent view ?
Use paddingTop
attribute.
Example:
<RelativeLayout
android:id="@+id/rlParentView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingTop="10dp"/>
</RelativeLayout>
Hope this will help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With