Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.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 2个文本视图平均填充剩余空间_Android_Android Layout - Fatal编程技术网

Android 2个文本视图平均填充剩余空间

Android 2个文本视图平均填充剩余空间,android,android-layout,Android,Android Layout,我正在尝试为ListView中的列表项进行以下布局。理想情况下,我希望布局具有5个文本视图,如下所示: 基本上,在上面一行中,我希望两端的两个文本视图的宽度固定,而其他两个视图平均分割剩余的空间。我找到了一些关于如何让一个文本视图填充剩余空间的建议,但没有找到关于两个文本视图如何平均分割空间的建议。生成的五个文本视图集应填充布局项 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http

我正在尝试为ListView中的列表项进行以下布局。理想情况下,我希望布局具有5个文本视图,如下所示: 基本上,在上面一行中,我希望两端的两个文本视图的宽度固定,而其他两个视图平均分割剩余的空间。我找到了一些关于如何让一个文本视图填充剩余空间的建议,但没有找到关于两个文本视图如何平均分割空间的建议。生成的五个文本视图集应填充布局项

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

    <TextView
        android:id = "@+id/s1"
        android:layout_width="50dip"
        android:layout_height = "50dip"
        android:text="what"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
    android:gravity="left"
        />
    <TextView
        android:id = "@+id/t1"
         android:layout_width="fill_parent"
        android:layout_height = "50dip"
        android:layout_toRightOf="@id/s1"
        android:text="why"
        android:layout_alignParentTop="true"
        />
    <TextView
        android:id = "@+id/t2"
         android:layout_width="fill_parent"
        android:layout_height = "50dip"
        android:layout_toRightOf="@id/t1"
        android:text="why"
        android:layout_alignParentTop="true"
        />
    <TextView
        android:id = "@+id/s2"
         android:layout_width="50dip"
        android:layout_height = "50dip"
        android:layout_toRightOf="@id/t2"
        android:text="what"
        android:gravity="right"
        android:layout_alignParentTop="true"

        />
    <TextView
        android:id = "@+id/bottom"
         android:layout_width="fill_parent"
        android:layout_height = "wrap_content"
        android:layout_below="@id/s1"
        android:text="what"
        android:gravity="center"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"

        />
    </RelativeLayout>

LinearLayout
替换父
RelativeLayout
(或者如果您不能添加额外的
LinearLayout
并将所有
textview
放入其中,然后将
android:layout\u weight=“1”
添加到所有
textview
,您想占据剩余空间的同等部分。

试试这个

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

<TextView
    android:id = "@+id/s1"
    android:layout_width="50dip"
    android:layout_height = "50dip"
    android:text="what"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:gravity="left" />

<TextView
    android:id = "@+id/s2"
    android:layout_width="50dip"
    android:layout_height = "50dip"
    android:text="what"
    android:gravity="right"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"/>

<LinearLayout
    android:layout_height="50dip"
    android:layout_width="match_parent"
    android:layout_toRightOf="@id/s1"
    android:layout_toLeftOf="@id/s2"
    android:layout_alignParentTop="true"
    android:orientation="horizontal" >

    <TextView
        android:id = "@+id/t1"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height = "match_parent"
        android:text="why"/>

    <TextView
        android:id = "@+id/t2"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height = "match_parent"
        android:text="why" />

</LinearLayout>

<TextView
    android:id = "@+id/bottom"
    android:layout_width="fill_parent"
    android:layout_height = "wrap_content"
    android:layout_below="@id/s1"
    android:text="what"
    android:gravity="center"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true" />
</RelativeLayout>


这在相对长度上没有任何作用,这是正确的。我没有检查根布局的类型,更正了
s1
s2
视图是否始终具有静态宽度(50dip)?如果是-仅使用
相对长度
和任何其他
线性布局
s:)即可实现所需线性布局与重量扫描你可能会画一些东西,让你的意思的想法?阅读有点难理解。一张图片会很有帮助