Изменение размера таблицы в динамическом режиме - PullRequest
0 голосов
/ 22 июля 2011

У меня есть собственное представление списка, которое меняет размер при нажатии на одну из строк, добавляются новые строки. Когда действие загружается впервые, в табличном макете есть только одна строка и две кнопки (предыдущая и следующая). В настоящее время, если у меня есть мой список добавленных в таблицу и строка 2 содержит кнопки. Высота и ширина макета установлены на wrap_content.

Когда к списку добавляются новые строки, размер строки не изменяется и, во-вторых, расширяется, занимая пространство, которое было для кнопок. И поэтому в результате мои кнопки исчезают.

main.xml

<LinearLayout android:orientation="vertical" style="?fill_parent"
android:layout_weight="1">
<TableLayout style="?fill_parent" android:layout_weight="1" >
<TableRow android:id="@+id/tr1">
   <CustomList android:id="@+id/mainview" ndroid:layout_height="wrap_content"
   android:layout_width="wrap_content" />
</TableRow>
<TableRow android:layout_height="wrap_content" android:layout_width="match_parent">
   <Button android:layout_width="wrap_content" android:id="@+id/button1"
    android:text="@string/buttonPrevious" android:layout_height="wrap_content">         </Button>
  <Button android:layout_width="wrap_content" android:id="@+id/button2"
  android:text="@string/buttonNext" android:layout_height="wrap_content"></Button>
</TableRow>
</TableLayout>
</LinearLayout>

Как динамически обновить размер строки при добавлении новых строк в представления.? Спасибо

Ответы [ 2 ]

1 голос
/ 22 июля 2011

Замените TableLayout на RelativeLayout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" 
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <CustomList android:layout_above="@+id/btn_pnl" 
    android:id="@+id/mainview" 
    android:layout_height="fill_parent"
    android:layout_width="fill_parent" />
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/btn_pnl"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:layout_alignParentBottom="true">
        <Button android:layout_width="wrap_content" 
          android:id="@+id/button1"
          android:text="@string/buttonPrevious" 
          android:layout_height="wrap_content">
        </Button>
        <Button android:layout_width="wrap_content" 
          android:id="@+id/button2"
          android:text="@string/buttonNext" 
          android:layout_height="wrap_content"></Button>
    </LinearLayout>
</RelativeLayout>

Этот макет поместит ваши кнопки в нижней части экрана, в то время как ListView покроет весь экран.

0 голосов
/ 22 июля 2011

Не кладите CustomList в таблицу, используйте линейную раскладку для удерживания кнопок. Обратите особое внимание на атрибуты layout_weight, как показано в следующей разметке макета

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
    <CustomList android:id="@+id/mainview" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"/>
    <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/llButtons" android:layout_gravity="bottom" android:layout_weight="0">
        <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"></Button>
        <Button android:text="Button" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"></Button>
    </LinearLayout>
</LinearLayout>
...