【问题标题】:Setting same width or height of views in XML在 XML 中设置相同的视图宽度或高度
【发布时间】:2010-10-31 12:00:18
【问题描述】:

我开始学习 android 并且正在制作一个简单的游戏。在这个游戏中,我需要两个宽度相同的滚动列表,所以我在两个视图中都将 layout_weight 参数设置为“1”。但是当我运行程序时,滚动视图有不同的大小。第二个问题是我需要将 EditText 小部件设置得很低,所以我对 TableRows 做了同样的事情,但最后我必须将 weight 设置为 0.1 以达到所需的大小。

附:如果有错误,对不起我的英语

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/widget28"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TableRow
        android:id="@+id/widget29"
        android:layout_width="fill_parent"
        android:layout_weight="7"
        android:orientation="vertical" >

        <ScrollView
            android:id="@+id/widget34"
            android:layout_height="150px"
            android:layout_weight="1"
            android:background="#ffff00ff" >
        </ScrollView>

        <ScrollView
            android:id="@+id/widget35"
            android:layout_height="150px"
            android:layout_weight="1"
            android:background="#ff00ffff" >
        </ScrollView>
    </TableRow>

    <TableRow
        android:id="@+id/widget30"
        android:layout_width="fill_parent"
        android:layout_weight="0.1"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/widget36"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="Not editable"
            android:textSize="18sp" >
        </EditText>
    </TableRow>

</TableLayout>

【问题讨论】:

    标签: android xml view size


    【解决方案1】:

    问题解决了,我用 LinearLayout 替换了第二个 TableRow,一切都开始正常工作。我不知道为什么,但是两个 TableRows 都以某种方式连接并且改变第二个的宽度改变了第一个的宽度

    【讨论】:

      【解决方案2】:

      您的 ScrollView 位于同一表格行上。尝试将 layout_weight 改为 0.5。那么他们两个都应该得到一半的行。

      【讨论】:

      • 我将 layout_weight 更改为 0.5,但界面没有任何变化。
      • 另一件事是我添加了可聚焦的 TextViews 并将 OnClickListener 设置为它们,从而将一个字母添加到 EditText。当我运行程序并单击列表位置时 EditText 的宽度和左 scrollView 的宽度同样变化
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-14
      • 1970-01-01
      • 1970-01-01
      • 2021-03-31
      相关资源
      最近更新 更多