1

问题图像

我有一个包含以下视图和嵌套相对布局的相对布局。对于某些设备,屏幕底部有一个空白区域。我想将空间公平地分配给嵌套视图并viewgroups()填充屏幕。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@color/tdmubiobgd"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MasterActivity$DummySectionFragment" >

<Button
    android:id="@+id/ScanButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:text="Scan" />

<ImageView
    android:id="@+id/scan_adsView"
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:layout_alignLeft="@id/ScanButton"
    android:layout_alignParentTop="true"
    android:scaleType="fitXY"
    android:src="@drawable/ads" />

<RelativeLayout
    android:id="@+id/scan_header"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/scan_adsView"
    android:layout_below="@id/scan_adsView"
    android:layout_marginTop="10px"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/Scan_Image"
        android:layout_width="72px"
        android:layout_height="72px"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/Scan_Name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/Scan_Image"
        android:text="Name"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/Scan_DName"
        android:layout_width="80dip"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textView3"
        android:layout_alignParentRight="true"
        android:layout_gravity="right"
        android:gravity="right"
        android:text="DName "
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/Scan_Sex"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/Scan_Name"
        android:layout_toRightOf="@+id/Scan_Age"
        android:text="Male"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/Scan_Age"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/Scan_Sex"
        android:layout_alignBottom="@+id/Scan_Sex"
        android:layout_alignLeft="@+id/Scan_Name"
        android:text="30"
        android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>

<ImageView
    android:id="@+id/scan_level1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/scan_header"
    android:layout_below="@+id/scan_header"
    android:scaleType="fitXY"
    android:src="@drawable/l1warning" />

<RelativeLayout
    android:id="@+id/scan_master"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/scan_level"
    android:layout_below="@id/scan_level1"
    android:layout_marginTop="10px"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/scan_mname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="MinionRush"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/scan_mdetails"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/scan_mname"
        android:layout_below="@+id/scan_mname"
        android:text="DoodlePlay"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/scan_period"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/scan_mdetails"
        android:text="DartRace"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <ImageView
        android:id="@+id/scan_alarm"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="20dp"
        android:src="@drawable/alarm" />
</RelativeLayout>

<ImageView
    android:id="@+id/scan_level2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@id/scan_master"
    android:layout_below="@id/scan_master"
    android:scaleType="fitXY"
    android:layout_marginTop="10px"
    android:src="@drawable/toempty" />

<Gallery
    android:id="@+id/scan_gallery"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/scan_level2"
    android:layout_marginTop="10px"
    android:layout_alignParentLeft="true" />

    <ImageView
        android:id="@+id/faq"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/scan_gallery"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10px"
        android:scaleType="fitXY"
        android:src="@drawable/faq" />

</RelativeLayout>
4

5 回答 5

2

使用以下内容:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="#ffffff">

    <ImageView
    android:id="@+id/imageView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:src="@drawable/ic_launcher" />

    <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:layout_weight="1"
    android:background="#556677">
    </RelativeLayout>

    <Gallery
    android:id="@+id/gallery1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:background="#664411"/>

    <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:layout_weight="1"
    android:background="#997766">
    </RelativeLayout>
</LinearLayout>

希望对你有帮助....

于 2013-08-22T06:59:23.673 回答
1

使用线性布局作为您的父布局并赋予所有布局权重。

于 2013-08-22T06:39:56.650 回答
0

利用

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout     
android:layout_width="fill_parent"
android:layout_height="fill_parent"
orientation="vertical">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="0dp" 
android:layout_weight="1"
android:src="@drawable/ic_launcher" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp" 
android:layout_weight="1">
</RelativeLayout>

<Gallery
android:id="@+id/gallery1"
android:layout_width="match_parent"
android:layout_height="0dp" 
android:layout_weight="1"
/>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp" 
android:layout_weight="1">
</RelativeLayout>

</LinearLayout>
于 2013-08-22T07:23:08.430 回答
0

这是您问题的XML

  <?xml version="1.0" encoding="utf-8"?>

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:src="@drawable/ic_launcher" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
     android:layout_weight="1">
</RelativeLayout>

<Gallery
    android:id="@+id/gallery1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
     android:layout_weight="1" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
     android:layout_weight="1">
</RelativeLayout>

于 2013-08-22T06:45:09.490 回答
-1

使用线性布局并添加 android:layout:weight="1" 每个标签..如果你想使用相对布局,最好你应该得到屏幕尺寸并将它分成四个,如果你有四个视图

请参阅此链接以获取屏幕尺寸

于 2013-08-22T06:41:09.097 回答