Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.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
TableLayout,android:布局和重量,包括_Android_Xml_Android Layout - Fatal编程技术网

TableLayout,android:布局和重量,包括

TableLayout,android:布局和重量,包括,android,xml,android-layout,Android,Xml,Android Layout,我在表格布局中有一个包含6个布局的布局。我想在横向模式下执行此操作,因为在我的场景中,ScrollView会很尴尬 我有一个48dp高水平布局,其中包含一个方形ImageView、一个全重SeekBar和一个方形ImageButton。我在Java中为ImageView设置了可绘图项 在主布局中,我对每个列使用include,我正在尝试平衡列,因为它们只占屏幕的一半,顺便说一句,这是一个主题为Theme.Holo.Dialog的活动 然而,当我运行应用程序时,我得到了40-60%的不平衡视图。为

我在
表格布局中有一个包含6个布局的布局
。我想在横向模式下执行此操作,因为在我的场景中,
ScrollView
会很尴尬

我有一个48dp高水平布局,其中包含一个方形
ImageView
、一个全重
SeekBar
和一个方形
ImageButton
。我在Java中为
ImageView
设置了可绘图项

在主布局中,我对每个列使用
include
,我正在尝试平衡列,因为它们只占屏幕的一半,顺便说一句,这是一个主题为
Theme.Holo.Dialog
的活动

然而,当我运行应用程序时,我得到了40-60%的不平衡视图。为什么?我做错了什么

layout land/main.xml的一部分

<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
      ... >
...
<TableLayout
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:stretchColumns="1"
    android:layout_height="wrap_content">

    <TableRow android:layout_width="match_parent" android:layout_height="wrap_content">
        <include android:layout_weight="1" layout="@layout/toast_item" android:id="@+id/systemToast"/>
        <include android:layout_weight="1" layout="@layout/toast_item" android:id="@+id/ringerToast"/>
    </TableRow>

    <TableRow android:layout_width="match_parent" android:layout_height="wrap_content">
        <include android:layout_weight="1" layout="@layout/toast_item" android:id="@+id/notifyToast"/>
        <include android:layout_weight="1" layout="@layout/toast_item" android:id="@+id/mediaToast"/>
    </TableRow>

    <TableRow android:layout_width="match_parent" android:layout_height="wrap_content">
        <include android:layout_weight="1" layout="@layout/toast_item" android:id="@+id/alarmToast"/>
        <include android:layout_weight="1" layout="@layout/toast_item" android:id="@+id/inCallToast"/>
    </TableRow>

</TableLayout>
...
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="0dp"
   android:layout_height="48dp"
   android:layout_marginLeft="8dp"
   android:layout_marginRight="8dp"
   android:orientation="horizontal"
   android:gravity="center_vertical">

<ImageView
    android:id="@+id/icon"
    android:src="@drawable/ic_audio_alarm"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:scaleType="center"
    android:clickable="false"
    android:layout_weight="0"/>
<SeekBar
    android:layout_width="0dp"
    android:layout_height="48dp"
    android:layout_weight="1"
    android:gravity="center_vertical"
    android:layout_marginLeft="4dp"
    android:maxHeight="1000dp"
    android:layout_marginRight="4dp"
    android:id="@+id/seekbar"/>
<ImageButton
    android:id="@+id/schedules"
    android:layout_width="48dp"
    android:layout_height="match_parent"
    android:scaleType="center"
    android:layout_weight="0"
    android:src="@drawable/ic_action_event"
    android:background="?android:attr/selectableItemBackground"
/>
</LinearLayout>

...
...
layout land/toast_item.xml

<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
      ... >
...
<TableLayout
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:stretchColumns="1"
    android:layout_height="wrap_content">

    <TableRow android:layout_width="match_parent" android:layout_height="wrap_content">
        <include android:layout_weight="1" layout="@layout/toast_item" android:id="@+id/systemToast"/>
        <include android:layout_weight="1" layout="@layout/toast_item" android:id="@+id/ringerToast"/>
    </TableRow>

    <TableRow android:layout_width="match_parent" android:layout_height="wrap_content">
        <include android:layout_weight="1" layout="@layout/toast_item" android:id="@+id/notifyToast"/>
        <include android:layout_weight="1" layout="@layout/toast_item" android:id="@+id/mediaToast"/>
    </TableRow>

    <TableRow android:layout_width="match_parent" android:layout_height="wrap_content">
        <include android:layout_weight="1" layout="@layout/toast_item" android:id="@+id/alarmToast"/>
        <include android:layout_weight="1" layout="@layout/toast_item" android:id="@+id/inCallToast"/>
    </TableRow>

</TableLayout>
...
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="0dp"
   android:layout_height="48dp"
   android:layout_marginLeft="8dp"
   android:layout_marginRight="8dp"
   android:orientation="horizontal"
   android:gravity="center_vertical">

<ImageView
    android:id="@+id/icon"
    android:src="@drawable/ic_audio_alarm"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:scaleType="center"
    android:clickable="false"
    android:layout_weight="0"/>
<SeekBar
    android:layout_width="0dp"
    android:layout_height="48dp"
    android:layout_weight="1"
    android:gravity="center_vertical"
    android:layout_marginLeft="4dp"
    android:maxHeight="1000dp"
    android:layout_marginRight="4dp"
    android:id="@+id/seekbar"/>
<ImageButton
    android:id="@+id/schedules"
    android:layout_width="48dp"
    android:layout_height="match_parent"
    android:scaleType="center"
    android:layout_weight="0"
    android:src="@drawable/ic_action_event"
    android:background="?android:attr/selectableItemBackground"
/>
</LinearLayout>

我注意到你有
android:layou-weight
,但我似乎没有
android:weightSum

我建议您使用
android:weightSum=“2”
,这样您拥有
android:layout\u weight=“1”
的两个对象将均匀分布

根据报告:

如果有三个文本字段,其中两个声明 权重为1,而另一个没有权重,第三个文本字段 没有重量就不会增长,只会占据 它的内容。另外两个将相等地扩展以填充空间 测量完所有三个字段后剩余

如果第三个字段是 然后给定权重2(而不是0),则现在声明为更多 它比其他两个都重要,所以它得到了剩余总量的一半 空间,而前两个平均分享其余部分


在TableLayout或TableRow中?请尝试TableRow。尽管如此,我注意到您的
toast\u项目的线性布局中有weight=“0”。这基本上相当于
包装内容
。我不知道这是不是你想要的。它成功了,谢谢。我从来没有想到,
android:weightSum
会这么做。我很少使用
TableLayout
,而且
LinearLayout
从不需要这样做。谢谢。:)