Размер кнопки в таблице неверен. (Андроид)

Я пишу приложение для Android. Вот его макет XML:

 <ScrollView android:id="@+id/ScrollView01"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"  
        android:layout_gravity="left|top|bottom|right"
        android:layout_marginTop="80dip"
        android:layout_marginLeft="0dip"
        android:layout_marginRight="0dip"
        android:layout_marginBottom="60dip"

>

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/centerlayout"
    android:orientation="vertical"
    android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_gravity="left|right|top|bottom"
        android:layout_marginRight="20dip"
        android:layout_marginLeft="10dip"
        android:layout_marginBottom="120dip"    >

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >



    <TableRow>
         <Button android:text="Button" 
             android:layout_column="0"
            android:id="@+id/bookmarkbutton" 
            android:layout_width="230dip" 
            android:layout_height="30dip" 

            android:background="@drawable/red_btn"
            android:padding="14dp" 
           ></Button>


    </TableRow>


    </TableLayout>

   </LinearLayout>



</ScrollView>

и если я запускаю его, он отображает следующий экран: введите здесь описание изображения

Но когда я добавляю android:layout_gravity="left" к "Кнопке", размер кнопки уменьшается и показывает: enter image  описание здесь

Обратите внимание, если я изменяю ширину кнопки на android:layout_width="30dip", она показывает маленькие кнопки, введите описание изображения  здесь

но если я изменю его на больший размер, он не применит размер правильно, а максимальная ширина будет такой же, как у второго изображения.

Наконец, если я добавлю к нему новое текстовое представление, через

ScrollView android:id="@+id/ScrollView01"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"  
        android:layout_gravity="left|top|bottom|right"
        android:layout_marginTop="80dip"
        android:layout_marginLeft="0dip"
        android:layout_marginRight="0dip"
        android:layout_marginBottom="60dip"



>

         <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/centerlayout"
        android:orientation="vertical"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_gravity="left|right|top|bottom"
        android:layout_marginRight="20dip"
        android:layout_marginLeft="10dip"
        android:layout_marginBottom="120dip"


        >

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >



  <TableRow>
         <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/subjecttext"
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"
        android:lineSpacingExtra="10dip"
        android:padding="14dp" 
        />    
        </TableRow>

    <TableRow>
         <Button android:text="Button" 
             android:layout_column="0"
            android:id="@+id/bookmarkbutton" 
            android:layout_width="20dip" 
            android:layout_height="30dip" 
            android:background="@drawable/black_btn"
            android:padding="14dp" 
           ></Button>


    </TableRow>





</TableLayout>

        </LinearLayout>



        </ScrollView>

Он отображает следующее изображение, и размер кнопки больше не изменяется. Не могли бы вы сказать мне, что случилось?

введите здесь описание изображения


person Farid Ala    schedule 02.12.2011    source источник


Ответы (1)


Попробуйте использовать LinearLayout вместо TableLayout. Вот ваш код с LinearLayout:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/ScrollView01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:layout_gravity="left|top|bottom|right" 
    android:layout_marginTop="80dip" 
    android:layout_marginLeft="0dip" 
    android:layout_marginRight="0dip"
    android:layout_marginBottom="60dip">
    <LinearLayout android:id="@+id/centerlayout" 
                android:orientation="vertical" 
                android:layout_width="fill_parent" 
                android:layout_height="fill_parent"
                android:layout_gravity="left|right|top|bottom" 
                android:layout_marginRight="20dip" 
                android:layout_marginLeft="10dip" 
                android:layout_marginBottom="120dip">
        <TextView android:text="Very long text in textview" 
                android:textSize="20sp" android:id="@+id/subjecttext"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:lineSpacingExtra="10dip" 
                android:padding="14dp" />
        <Button android:id="@+id/bookmarkbutton" 
                android:background="@drawable/red_btn" 
                android:text="Button" 
                android:padding="14dp" 
                android:layout_height="30dip"
                android:layout_width="20dip">
        </Button>
    </LinearLayout>
</ScrollView>

И Скриншот:

введите здесь описание изображения

Надеюсь, это поможет вам!

Я действительно вижу, что ваши кнопки в кнопке экрана имеют обрезанный текст. Это вторая проблема?

Ниже я приложил скриншот с кодом:

введите здесь описание изображения

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/ScrollView01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:layout_gravity="left|top|bottom|right" 
    android:layout_marginTop="80dip" 
    android:layout_marginLeft="0dip" 
    android:layout_marginRight="0dip"
    android:layout_marginBottom="60dip">
    <LinearLayout android:id="@+id/centerlayout" 
                android:orientation="vertical" 
                android:layout_width="fill_parent" 
                android:layout_height="fill_parent"
                android:layout_gravity="left|right|top|bottom" 
                android:layout_marginRight="20dip" 
                android:layout_marginLeft="10dip" 
                android:layout_marginBottom="120dip">
        <TextView android:text="Very long text in textview" 
                android:textSize="20sp" android:id="@+id/subjecttext"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:lineSpacingExtra="10dip" 
                android:padding="14dp" />
        <Button android:text="Button" 
                android:background="@drawable/red_btn" 
                android:id="@+id/button1" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"></Button>
    </LinearLayout>
</ScrollView>
person ihrupin    schedule 02.12.2011
comment
Большое спасибо. Это работает нормально. Вы сэкономили мне много времени. - person Farid Ala; 03.12.2011