<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="5"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/layout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
<ImageView
android:id="@+id/im11"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/munshee_logo" />
<ImageView
android:id="@+id/im12"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/munshee_logo" />
<ImageView
android:id="@+id/im13"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/munshee_logo" />
<ImageView
android:id="@+id/im14"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/munshee_logo" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/layout1"
android:layout_weight="1"
android:layout_centerHorizontal="true" >
<ImageView
android:id="@+id/im31"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/munshee_logo" />
<ImageView
android:id="@+id/im32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/munshee_logo" />
<ImageView
android:id="@+id/im33"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/munshee_logo" />
<ImageView
android:id="@+id/im34"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/munshee_logo" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/layout2"
android:layout_centerHorizontal="true" >
<ImageView
android:id="@+id/im41"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/munshee_logo" />
<ImageView
android:id="@+id/im42"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/munshee_logo" />
<ImageView
android:id="@+id/im43"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/munshee_logo" />
<ImageView
android:id="@+id/im44"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/munshee_logo" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/layout3"
android:layout_weight="1"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<ImageView
android:id="@+id/im51"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/munshee_logo" />
<ImageView
android:id="@+id/im52"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/munshee_logo" />
<ImageView
android:id="@+id/im53"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/munshee_logo" />
<ImageView
android:id="@+id/im54"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/munshee_logo" />
</LinearLayout>
</RelativeLayout>
我希望linear layouts
调整其高度,以便所有5 linear layouts
适合屏幕。
答案 0 :(得分:1)
您不需要
Relative Layout
作为Root Layout
。因为您可以Linear Layout
作为Root Layout
执行此操作。使用Weight
属性。
这是xml 。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/layout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:weightSum="4">
<ImageView
android:id="@+id/im11"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
<ImageView
android:id="@+id/im12"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
<ImageView
android:id="@+id/im13"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
<ImageView
android:id="@+id/im14"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:weightSum="4">
<ImageView
android:id="@+id/im31"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
<ImageView
android:id="@+id/im32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
<ImageView
android:id="@+id/im33"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
<ImageView
android:id="@+id/im34"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:weightSum="4">
<ImageView
android:id="@+id/im41"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
<ImageView
android:id="@+id/im42"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
<ImageView
android:id="@+id/im43"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
<ImageView
android:id="@+id/im44"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:weightSum="4">
<ImageView
android:id="@+id/im51"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
<ImageView
android:id="@+id/im52"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
<ImageView
android:id="@+id/im53"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
<ImageView
android:id="@+id/im54"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:weightSum="4">
<ImageView
android:id="@+id/im1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
<ImageView
android:id="@+id/im2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
<ImageView
android:id="@+id/im3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
<ImageView
android:id="@+id/im4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/common_ic_googleplayservices" />
</LinearLayout>
</LinearLayout>
答案 1 :(得分:0)
尝试此代码....
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="5"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/layout1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:id="@+id/im11"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/im12"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/im13"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/im14"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout2"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:id="@+id/im31"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/im32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/im33"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/im34"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout3"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1">
<ImageView
android:id="@+id/im41"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/im42"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/im43"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/im44"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout4"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:id="@+id/im51"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/im52"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/im53"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/im54"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
</LinearLayout>
答案 2 :(得分:0)
从相对和线性布局中删除所有android:layout_weight
行