Android 相同高度的定心布局
我无法通过imgur上传图像,因此我将通过驱动器发布链接: 以下是xml:Android 相同高度的定心布局,android,xml,layout,Android,Xml,Layout,我无法通过imgur上传图像,因此我将通过驱动器发布链接: 以下是xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:la
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/lay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/imgView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
<ImageView
android:id="@+id/imgView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:id="@+id/lay2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/lay"
android:orientation="horizontal">
<ImageView
android:id="@+id/imgView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
<ImageView
android:id="@+id/imgView4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/buttonLoadPicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Load Picture"
android:layout_centerInParent="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
我需要的是制作布局中心,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:id="@+id/lay"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="2"
android:orientation="horizontal">
<ImageView
android:id="@+id/imgView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
<ImageView
android:id="@+id/imgView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:id="@+id/lay2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@+id/lay"
android:orientation="horizontal"
android:layout_weight="1"
android:weightSum="2">
<ImageView
android:id="@+id/imgView3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
<ImageView
android:id="@+id/imgView4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/buttonLoadPicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Load Picture"
android:layout_centerInParent="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
请帮忙,提前谢谢 您也应该在垂直布局中使用
权重。
请尝试此代码。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/lay"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<ImageView
android:id="@+id/imgView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
<ImageView
android:id="@+id/imgView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:id="@+id/lay2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@+id/lay"
android:orientation="horizontal"
android:layout_weight="1">
<ImageView
android:id="@+id/imgView3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
<ImageView
android:id="@+id/imgView4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/buttonLoadPicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Load Picture"
android:layout_centerInParent="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
您也应该在垂直布局中使用权重。
请尝试此代码。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/lay"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<ImageView
android:id="@+id/imgView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
<ImageView
android:id="@+id/imgView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:id="@+id/lay2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@+id/lay"
android:orientation="horizontal"
android:layout_weight="1">
<ImageView
android:id="@+id/imgView3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
<ImageView
android:id="@+id/imgView4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/buttonLoadPicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Load Picture"
android:layout_centerInParent="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
必须将weightSum
属性添加到LinearLayout,并为图像视图的android:layout\u width
设置0dp
,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:id="@+id/lay"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="2"
android:orientation="horizontal">
<ImageView
android:id="@+id/imgView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
<ImageView
android:id="@+id/imgView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:id="@+id/lay2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@+id/lay"
android:orientation="horizontal"
android:layout_weight="1"
android:weightSum="2">
<ImageView
android:id="@+id/imgView3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
<ImageView
android:id="@+id/imgView4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/buttonLoadPicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Load Picture"
android:layout_centerInParent="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
必须将weightSum
属性添加到LinearLayout,并为图像视图的android:layout\u width
设置0dp
,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:id="@+id/lay"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="2"
android:orientation="horizontal">
<ImageView
android:id="@+id/imgView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
<ImageView
android:id="@+id/imgView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:id="@+id/lay2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@+id/lay"
android:orientation="horizontal"
android:layout_weight="1"
android:weightSum="2">
<ImageView
android:id="@+id/imgView3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
<ImageView
android:id="@+id/imgView4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/buttonLoadPicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Load Picture"
android:layout_centerInParent="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>