Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.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_Android Layout_Android Widget - Fatal编程技术网

Android 如何定制布局(高度和宽度)以及布局的集装箱船?

Android 如何定制布局(高度和宽度)以及布局的集装箱船?,android,android-layout,android-widget,Android,Android Layout,Android Widget,我创建了一个包含两行的表格布局,其中第一行有一个文本视图,第二行有两列,第一行有一个列表视图,第二行有一个编辑文本和一个按钮。我希望两行高度相等(正好是屏幕的一半),第二行的两列宽度相等(正好是屏幕的一半)。我想建造这样的东西: 我应该如何进行?我应该选择哪种布局?我认为您当前的解决方案行不通(因为需要相等的空间(宽度和高度)+列表视图的存在)。一种解决方案是使用嵌套的权重(这对性能不利,但(可能在不知道自己做了什么的情况下)不会破坏应用程序),如以下布局: <?xml version="

我创建了一个包含两行的
表格布局
,其中第一行有一个
文本视图
,第二行有两列,第一行有一个
列表视图
,第二行有一个
编辑文本
和一个
按钮
。我希望两行高度相等(正好是屏幕的一半),第二行的两列宽度相等(正好是屏幕的一半)。我想建造这样的东西:


我应该如何进行?我应该选择哪种布局?

我认为您当前的解决方案行不通(因为需要相等的空间(宽度和高度)+
列表视图的存在)。一种解决方案是使用嵌套的
权重(这对性能不利,但(可能在不知道自己做了什么的情况下)不会破坏应用程序),如以下布局:

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

    <include
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        layout="@layout/identical_layout" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:text="TextView" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <ListView
            android:id="@+id/list"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1" >
        </ListView>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:orientation="vertical" >

            <EditText
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />

            <Button
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="ddd" />
        </LinearLayout>
    </LinearLayout>




</LinearLayout>

相同的\u布局
布局文件代表您的
活动所共享的公共布局

+1000谢谢您真的很棒,目前我正试图通过TableLayout实现这一点,但是您的回答让我感到轻松,我正在尝试实现第一个选项。。。如果它们是一些性能开销,我肯定会选择第二种方法。。。再次感谢你…这起作用了。。。现在唯一的问题是ListView没有滚动,我该怎么做???再次感谢十亿…@anDroider我不知道为什么你的
列表视图不滚动。有一些东西与你的代码有关,而不是上面的布局文件,因为我现在测试它们,
ListView
按预期工作。它第一次工作,但如果焦点到达EditText,ListView在那之后就不会滚动了。我使用的代码与你回答中提到的相同…(嵌套权重)为了便于说明,我设置了一些示例字符串值(如我同事的随机名称),一切正常(都要感谢您)。。。但是,一旦焦点进入最后一个线性布局,之后即使我多次单击它,ListView也不会滚动。。。我正在API 2.3.3(10)模拟器上测试它。。。
<?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="fill_parent" >

    <include
        android:id="@+id/included_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        layout="@layout/identical_layout" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/included_layout" >

        <View
            android:id="@+id/anchor"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_centerVertical="true" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_above="@id/anchor"
            android:layout_alignParentTop="true"
            android:background="#99cc00"
            android:text="TextView" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_alignParentBottom="true"
            android:layout_below="@id/anchor" >

            <ListView
                android:id="@+id/list"
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1" >
            </ListView>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:orientation="vertical" >

                <EditText
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" />

                <Button
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="ddd" />
            </LinearLayout>
        </LinearLayout>
    </RelativeLayout>

</RelativeLayout>