Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.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布局与相对布局_Android_Layout_Android Relativelayout - Fatal编程技术网

Android布局与相对布局

Android布局与相对布局,android,layout,android-relativelayout,Android,Layout,Android Relativelayout,有人能解释一下为什么下面的代码片段不能按预期工作吗? 我不能在第一个文本视图中使用android:layout\u alignParentBottom=“true”参数,因为这样做会使视图位于整个屏幕的底部 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_widt

有人能解释一下为什么下面的代码片段不能按预期工作吗? 我不能在第一个文本视图中使用
android:layout\u alignParentBottom=“true”
参数,因为这样做会使视图位于整个屏幕的底部

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

    <TextView 
        android:id="@+id/bottom_text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/color_black"
        android:text="AT THE BOTTOM OF THE LAYOUT"/>


     <TextView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/bottom_text_view"
        android:textColor="@color/color_black"
        android:text="ABOVE THE PREVIOUS TEXT VIEW"/>

</RelativeLayout>
试试这个

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

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView2"
        android:text="AT THE BOTTOM OF THE LAYOUT" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="ABOVE THE PREVIOUS TEXT VIEW" />

</RelativeLayout>


这是因为您将
相对长度的
高度设置为
包裹内容
在我对代码稍作修改后复制它,看看它将如何工作

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

    <TextView 
        android:id="@+id/bottom_text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/color_black"
        android:text="AT THE BOTTOM OF THE LAYOUT"/>


     <TextView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/bottom_text_view"
        android:textColor="@color/color_black"
        android:text="ABOVE THE PREVIOUS TEXT VIEW"/>

</RelativeLayout>

这是我刚刚创建的布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="52dp"
        android:textSize="30sp"
        android:text="Hi I'm The Text On TOP" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="40dp"
        android:text="Hi I'm The Text Below the Text Above"
        android:textSize="30sp" />

</RelativeLayout>


他的问题是相对高度是包裹内容,布局将位于顶部,而不是填充父级!这不适合我的情况,因为正如我所说的,真正的用例将让列表视图以这种方式获得所有可用空间。嘿,等一下,也许值得一试……我会让你知道的。我尝试了使用列表视图的解决方案,它占用了我所怀疑的所有空间。我将编辑我的文章,以提供我真正的布局,希望你能帮助我。也许我做了一些错事谢谢你的回答但结果没有改变:(再次感谢,但是如果放在顶部的视图是一个空间贪婪的视图,例如ListView,这将不起作用。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="52dp"
        android:textSize="30sp"
        android:text="Hi I'm The Text On TOP" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="40dp"
        android:text="Hi I'm The Text Below the Text Above"
        android:textSize="30sp" />

</RelativeLayout>