1

我正在尝试使用以下视图小部件组织我的视图 -

  • TextView(应该填满屏幕的宽度并具有特定的高度)
  • 使用 Draw() 绘制的自定义视图(填充宽度,应该在上面的 textview 之后开始并填充屏幕)

我正在尝试编写棋盘游戏,因此绘制了自定义视图。

我的问题是为此使用的最佳布局是什么?

我可以使用 TableLayout 并将这两个视图分别作为一列吗?我认为这可以解决问题,但我用于自定义视图的任何布局都不会填满屏幕,即使我正在绘制它的 tablerow 填满了屏幕。

我希望我能够正确地解释自己。非常感谢任何指针。

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

        <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/tl_question"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:shrinkColumns="1"
            android:stretchColumns="2">

            <TableRow>
                <TextView
                    android:id="@+id/question"
                    android:layout_width="wrap_content"
                    android:textSize="30sp"
                    android:textColor="#ffFFFFFF"   
                    android:layout_gravity="center_vertical"
                    android:paddingBottom="9dip"
                    android:layout_marginLeft="3dip"
                    android:layout_marginRight="2dip"/>
            </TableRow>

            <TableRow>
                <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_gravity="center_vertical" >
                    <com.ac.gui.CustomView
                        android:id="@+id/custom_board"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:keepScreenOn="true" />
                </LinearLayout>
            </TableRow>
        </TableLayout>

</RelativeLayout>
4

1 回答 1

0

尝试使用这个

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


            <TextView
                android:id="@+id/question"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textSize="30sp"
                android:text="ASDFASDF"
                android:textColor="#ffFFFFFF"   
                android:layout_gravity="center_vertical"
                android:paddingBottom="9dip"
                android:layout_marginLeft="3dip"
                android:layout_marginRight="2dip"/>

           <com.ac.gui.CustomView

            android:layout_below="@+id/question"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" />

</RelativeLayout>

我测试了一个不同的布局来代替你的布局,它工作正常。它也应该适用于你的。

RelativeLayout 允许您相对于彼此定位项目。您会注意到自定义视图上的属性“layout_below”,我在其中指定了要放置它的视图的 ID。

于 2011-06-10T00:29:15.060 回答