English 中文(简体)
和机器人:当包装内容 不只是包装内容?
原标题:Android: when wrap_content doesn t just wrap its content?

我的项目有以下的xml布局(顺便说一句,如果你注意到其他看似错误/不太好的东西, 我很感激你让我知道! ) 而我的问题是 上次文本查看(“ EEE, txt4 ”) 的属性“ lob_ contents” 不起作用?

<?xml version="1.0" encoding="utf-8"?>

<merge xmlns:android="http://schemas.android.com/apk/res/android">

    <TableLayout
        android:id="@+id/Table"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical">


            <TextView
                android:id="@+id/txt1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:text="AAA"
                android:textColor="@color/white" />


            <Spinner
                android:id="@+id/spn1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:entries="@array/array1" />

        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >


            <TextView
                android:id="@+id/edt1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:text="BBB"
                android:textColor="@color/white" />

            <Spinner
                android:id="@+id/spn2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:entries="@array/Tounyuhou" />

            <EditText
                android:id="@+id/edt2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ems="5"
                android:inputType="numberSigned"/>

            <TextView
                android:id="@+id/txt2"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="CCC" android:textColor="@color/white" 
                android:gravity="center_vertical|center_horizontal" 
                android:textSize="18sp"/>

        </TableRow>

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">



            <TextView
                android:id="@+id/txt3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical|center_horizontal"
                android:text="DDD"
                android:textColor="@color/white" />



            <EditText
                android:id="@+id/edt3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="right|center_vertical">

            </EditText>


            <TextView
                android:id="@+id/txt4"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="EEE"
                android:textColor="@color/white"
                android:gravity="center_vertical|center_horizontal"
                android:textSize="20sp"/>

        </TableRow>


        </TableLayout>

</merge>
最佳回答

在此您定义所有行的布局相同, 但视图数量不同, 如第1行包含 2, 第2行包含 4, 第3行包含 3 视图,

故它有问题,

所以我的土豆要用三排不同的桌布

<?xml version="1.0" encoding="utf-8"?>

<merge xmlns:android="http://schemas.android.com/apk/res/android">

 <TableLayout
            android:id="@+id/mainTable"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">

            <TableRow
                android:id="@+id/mainTable_tableRow1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical">

        <TableLayout
            android:id="@+id/Table"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical">


                <TextView
                    android:id="@+id/txt1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:text="AAA"
                    android:textColor="@color/white" />


                <Spinner
                    android:id="@+id/spn1"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:entries="@array/array1" />

            </TableRow>

            <TableRow
                android:id="@+id/tableRow2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >


                <TextView
                    android:id="@+id/edt1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:text="BBB"
                    android:textColor="@color/white" />

                <Spinner
                    android:id="@+id/spn2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:entries="@array/Tounyuhou" />

                <EditText
                    android:id="@+id/edt2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:ems="5"
                    android:inputType="numberSigned"/>

                <TextView
                    android:id="@+id/txt2"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:text="CCC" android:textColor="@color/white" 
                    android:gravity="center_vertical|center_horizontal" 
                    android:textSize="18sp"/>

            </TableRow>
    </TableLayout>
</TableRow>
<TableRow
                android:id="@+id/mainTable_tableRow2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical">
    <TableLayout
            android:id="@+id/Table2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">

            <TableRow
                android:id="@+id/table2_tableRow3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">



                <TextView
                    android:id="@+id/txt3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical|center_horizontal"
                    android:text="DDD"
                    android:textColor="@color/white" />



                <EditText
                    android:id="@+id/edt3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right|center_vertical">

                </EditText>


                <TextView
                    android:id="@+id/txt4"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:text="EEE"
                    android:textColor="@color/white"
                    android:gravity="center_vertical|center_horizontal"
                    android:textSize="20sp"/>

            </TableRow>


            </TableLayout>
</TableRow>
 </TableLayout>

    </merge>
问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签