Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/366.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
Java 在具有不同组件的Android中设置表布局中列的相等宽度_Java_Android - Fatal编程技术网

Java 在具有不同组件的Android中设置表布局中列的相等宽度

Java 在具有不同组件的Android中设置表布局中列的相等宽度,java,android,Java,Android,我看过这个问题 看到答案后,列的大小确实相同,但当我用EditText替换两个TextView时,相同的大小不再出现。我怎样才能解决这个问题 这是修改后的代码: <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/to

我看过这个问题

看到答案后,列的大小确实相同,但当我用EditText替换两个TextView时,相同的大小不再出现。我怎样才能解决这个问题

这是修改后的代码:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_calendar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:stretchColumns="*"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_calendar">

<TableRow android:layout_width="0dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity=""
        android:text="table header1"
        android:textSize="10dip"
        android:textStyle="bold" />

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="table header3"
        android:textSize="10dip"
        android:textStyle="bold" />

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="table header4"
        android:textSize="10dip"
        android:textStyle="bold" />
</TableRow>
</TableLayout>

试试这个:

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/content_calendar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:stretchColumns="*"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <TableRow android:layout_width="0dp">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">


            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity=""
                android:text="table header1"
                android:textSize="10dip"
                android:textStyle="bold" />

            <EditText
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="table header3"
                android:textSize="10dip"
                android:textStyle="bold" />

            <EditText
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="table header4"
                android:textSize="10dip"
                android:textStyle="bold" />
        </LinearLayout>
    </TableRow>
</TableLayout>

试试这个:

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/content_calendar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:stretchColumns="*"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <TableRow android:layout_width="0dp">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">


            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity=""
                android:text="table header1"
                android:textSize="10dip"
                android:textStyle="bold" />

            <EditText
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="table header3"
                android:textSize="10dip"
                android:textStyle="bold" />

            <EditText
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="table header4"
                android:textSize="10dip"
                android:textStyle="bold" />
        </LinearLayout>
    </TableRow>
</TableLayout>

下面的代码可能会帮助您实现您想要的目标

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    android:fitsSystemWindows="true"
    >
    <TableLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/main"
        >

        <!-- name -->
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:drawable/dialog_holo_light_frame"
            android:padding="@dimen/activity_horizontal_margin">
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textAppearance="   android:attr/textAppearanceMedium"
                android:text="name:"
                android:textColor="@android:color/background_dark"
                android:id="@+id/name"/>
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
               android:textAppearance="android:attr/textAppearanceMedium"
                android:text="user"
                android:textColor="@android:color/background_dark"
                android:id="@user"/>
        </TableRow>

        <!-- phone number -->
        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@android:drawable/dialog_holo_light_frame"
            android:padding="@dimen/activity_horizontal_margin">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
               android:textAppearance="android:attr/textAppearanceMedium"
                android:text="phone number:"
                android:textColor="@android:color/background_dark"
                android:id="@+id/phonenumber"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
               android:textAppearance="android:attr/textAppearanceMedium"
                android:text="1234567890"
                android:textColor="@android:color/background_dark"
                android:id="@+id/number"/>
        </TableRow>

        <!-- address -->
        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@android:drawable/dialog_holo_light_frame"
            android:padding="@dimen/activity_horizontal_margin">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="current address:"
                android:textColor="@android:color/background_dark"
                android:id="@+id/currentaddress"/>
            <TextView
                android:layout_height="wrap_content"
               android:textAppearance="android:attr/textAppearanceMedium"
                android:text="xyz"
                android:textColor="@android:color/background_dark"
                android:id="@+id/address"/>
        </TableRow>

    </TableLayout>

</ScrollView>

下面的代码可能会帮助您实现您想要的目标

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    android:fitsSystemWindows="true"
    >
    <TableLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/main"
        >

        <!-- name -->
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:drawable/dialog_holo_light_frame"
            android:padding="@dimen/activity_horizontal_margin">
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textAppearance="   android:attr/textAppearanceMedium"
                android:text="name:"
                android:textColor="@android:color/background_dark"
                android:id="@+id/name"/>
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
               android:textAppearance="android:attr/textAppearanceMedium"
                android:text="user"
                android:textColor="@android:color/background_dark"
                android:id="@user"/>
        </TableRow>

        <!-- phone number -->
        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@android:drawable/dialog_holo_light_frame"
            android:padding="@dimen/activity_horizontal_margin">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
               android:textAppearance="android:attr/textAppearanceMedium"
                android:text="phone number:"
                android:textColor="@android:color/background_dark"
                android:id="@+id/phonenumber"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
               android:textAppearance="android:attr/textAppearanceMedium"
                android:text="1234567890"
                android:textColor="@android:color/background_dark"
                android:id="@+id/number"/>
        </TableRow>

        <!-- address -->
        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@android:drawable/dialog_holo_light_frame"
            android:padding="@dimen/activity_horizontal_margin">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="current address:"
                android:textColor="@android:color/background_dark"
                android:id="@+id/currentaddress"/>
            <TextView
                android:layout_height="wrap_content"
               android:textAppearance="android:attr/textAppearanceMedium"
                android:text="xyz"
                android:textColor="@android:color/background_dark"
                android:id="@+id/address"/>
        </TableRow>

    </TableLayout>

</ScrollView>