Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 视图不';t匹配它';父母_Android_Xml Layout - Fatal编程技术网

Android 视图不';t匹配它';父母

Android 视图不';t匹配它';父母,android,xml-layout,Android,Xml Layout,尽管我有一年多的安卓操作经验,但我确实在为我的xml布局苦苦挣扎:)。无论如何,我需要创建一个xml布局,如下所示: 我试过这个: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_par

尽管我有一年多的安卓操作经验,但我确实在为我的xml布局苦苦挣扎:)。无论如何,我需要创建一个xml布局,如下所示:

我试过这个:

<?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="100">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp" 
    android:layout_weight="5">
</RelativeLayout>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp" 
    android:layout_weight="15">
</RelativeLayout>
 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp" 
    android:layout_weight="5" >
</RelativeLayout>
 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp" 
    android:layout_weight="20" >
</RelativeLayout>
 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp" 
    android:layout_weight="5" >
</RelativeLayout>
 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp" 
    android:layout_weight="50" >
</RelativeLayout>

</LinearLayout>

在我想把孩子添加到一些内部布局之前,一切看起来都很好。 因此,当我将listView添加到RelativeLayout中,并用数字3标记时,它与 但家长却占据了整个屏幕。如何将listview添加到内部布局2和3,以便
匹配它们的边界?

看看这段演示代码,也许你可以在这段代码中做一些更改,并将其应用于你的使用。 直接将此代码放入xml中

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

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

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/com_facebook_button_grey_focused" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.3" 
        android:layout_margin="10dp"
        >

        <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ListView>
    </RelativeLayout>

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

        <ListView
            android:id="@+id/listView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ListView>
    </RelativeLayout>

</LinearLayout>


可能会将所有版面的
版面高度设置为
wrap\u content
?我尝试使用match\u parent和wrap\u content,但在这两种情况下,listView(或imageView,如果我将其添加到版面1中)占据整个屏幕。都德尝试从头到脚进行操作。您的方法是正确的,请查看您使用的图像的尺寸是否在您想要的范围内。我认为问题在于您在
RelativeLayouts
中添加的内容没有限制
包装内容
?请注意,在声明内容的视图中使用
match\u parent
是没有意义的,我真的不知道,但您应该将布局分为两部分:一部分包含listview上面的所有元素,另一部分包含listview。感谢您的努力,但我只能看到两个包含listview的listview占据整个屏幕。这对我来说很有用。。你确定你复制粘贴的正确吗?@simon:你可以说XML也是一种代码。但它是结构化的。@prowebphoneapp:除了两个列表视图之外,你必须在最上面的相对布局中看到某种图像。它可以工作,但我需要在布局之间留出空白,如上图所示,你能编辑你的答案吗?