I want to put content items evenly by vertical in LinearLayout on my Android screen, but items cuddle to top. How to fix it? Here is my screen in xml-code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:weightSum="1"
android:layout_gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/olumn128"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Login"
android:id="@+id/textView2"
android:layout_gravity="center" />
</LinearLayout>
</LinearLayout>
First is that you don't need nested LinearLayout
to achieve what you want. So you can remove your second LinearLayout
.
To make views occupy height of screen evenly, you can use android:layout_weight="1"
then set your android:layout_height="0dp"
. Set those attributes to the views you want to have equal height.
Also, remove your weightSum
in the LinearLayout
, because by setting the layout_weight
of your views equal to 1, you are implicitly telling that the weightSum
is 2 and that your views are sharing it equally.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.