Таблица слишком широка, даже при совпадении родителей в Android Studio - PullRequest
0 голосов
/ 02 октября 2018

Я пытался создать приложение для задания, в котором я использовал таблицу, однако экран предварительного просмотра был больше экрана моего телефона, поэтому таблица оказалась слишком большой, мне сказали использовать родительский матччтобы автоматически настроить таблицу в соответствии с размером экрана на телефоне, однако это не помогло, поэтому я ищу помощь. Снимок экрана проблемы Правка.выпуск.

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textview1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="TOY CARS" />

    <TableLayout
        android:id="@+id/table1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textview1"
        android:stretchColumns="0,1,2,3,4">

        <TableRow>

            <TextView
                android:id="@+id/textview2"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_column="0"
                android:text="Hot Wheels" />

            <TextView
                android:layout_column="1"
                android:text="$50"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

            <Button
                android:id="@+id/button1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_column="2"
                android:text="ADD" />
            <Button
                android:id="@+id/button2"
                android:text="REMOVE"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_column="3"/>
            <TextView
                android:id="@+id/textview6"
                android:text="0"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_column="4"/>
        </TableRow>

        <TableRow>

            <TextView
                android:id="@+id/textview3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_column="0"
                android:text="Trandformers" />

            <TextView
                android:layout_column="1"
                android:text="$100" />
            <Button
                android:id="@+id/button3"
                android:text="ADD"/>
            <Button
                android:id="@+id/button4"
                android:text="REMOVE"/>
            <TextView
                android:id="@+id/textview7"
                android:text="0"/>
        </TableRow>

        <TableRow>

            <TextView
                android:id="@+id/textview4"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_column="0"
                android:text="Tonka" />
            <TextView
                android:layout_column="1"
                android:text="$150" />
            <Button
                android:id="@+id/button5"
                android:text="ADD"/>
            <Button
                android:id="@+id/button6"
                android:text="REMOVE"/>
            <TextView
                android:id="@+id/textview8"
                android:text="0"/>
        </TableRow>

        <TableRow>

            <TextView
                android:id="@+id/textview5"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_column="0"
                android:text="ZipZaps" />
            <TextView
                android:layout_column="1"
                android:text="$200" />
            <Button
                android:id="@+id/button7"
                android:text="ADD"/>
            <Button
                android:id="@+id/button8"
                android:text="REMOVE"/>
            <TextView
                android:id="@+id/textview9"
                android:text="0"/>
        </TableRow>

        <TableRow>
            <TextView
                android:id="@+id/textview10"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Coupon Code: "
                android:layout_column="0"/>

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="Coupon Code"
                android:layout_toRightOf="@+id/textview10"/>
        </TableRow>

        <TableRow>
            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:text="VAT"/>
        </TableRow>
    </TableLayout>
    <TextView
        android:id="@+id/textview11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Area Code"
        android:layout_below="@+id/table1"/>
    <RadioGroup
        android:id="@+id/radiogroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textview11">
        <RadioButton
            android:id="@+id/radiobutton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="33100-34000"/>
        <RadioButton
            android:id="@+id/radiobutton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="34000-35001"/>
        <RadioButton
            android:id="@+id/radiobutton3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="00000"/>
    </RadioGroup>

    <Button
        android:id="@+id/button9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/radiogroup1"
        android:text="Calculate"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="$00000"
        android:layout_below="@+id/radiogroup1"
        android:layout_toRightOf="@+id/button9"
        android:layout_marginLeft="20px"
        android:textSize="25dp"/>



</RelativeLayout>

1 Ответ

0 голосов
/ 02 октября 2018

Я бы попытался добавить атрибут android:shrinkColumns так же, как вы добавили атрибут android:stretchColumns.Атрибут stretchColumns позволяет растягивать столбцы таблицы до большого родителя, а атрибут shrinkColumns позволяет им сжиматься до маленького родителя.Вы можете иметь оба атрибута на макете одновременно, и они оба будут работать.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...