Android галерея динамически изменяет высоту - PullRequest
1 голос
/ 17 февраля 2012

Я хочу сделать горизонтальную галерею для выполнения пользовательских видов: например, хотите иметь массив продуктов с его описанием, ценой и фото, Я создаю пользовательский макет и переопределяю getView и адаптер.

Текст описания может быть слишком большим, и я возвращаю только небольшую его часть и загружаю в представление. Есть кнопка «еще», чтобы расширить это представление. Ниже галереи есть другой вид макета с некоторыми кнопками, элементами управления и т. Д.

OnMoreButtonClick Я устанавливаю только полный текст описания TextView. Высота галереи Я обертываю содержимое и думаю, что оно должно динамически менять размер.

Кстати, если я загружу полный текст без короткого - все в порядке.

Это главный экран приложения, когда я нажимаю кнопку, я хочу, чтобы элемент галереи растягивался и тянул TimeAndDatePicker вниз.

Gallery with items and a button (like

Но когда я нажимаю на нее, я вижу только:

But when I press it I can only see:

И если я загружаю полный текст без малого, все в порядке:

And if I load the full text without small one everything is ok

main.xml:

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

android:layout_width="fill_parent"
android:id = "@+id/scene"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/main_background" >

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
            <ru.human.samples.CustomGallery
              android:id="@+id/galleryUnique"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:gravity="center"
              android:spacing="1dp" android:unselectedAlpha="255.0" android:visibility="visible" android:fadingEdge="none"/>
           <DatePicker
        android:id="@+id/datePicker1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    </LinearLayout>



</ScrollView>

и galleryItem xml:

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

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="15dp"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        style="@style/PriceText"
        android:text="Medium Text"/>

</LinearLayout>

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    style="@style/BodyText"
    android:text="TextView" />

 <TextView
    android:id="@+id/description"
    android:layout_width="match_parent"
    style="@style/BodyText"
    android:text="Medium Text"
    android:layout_height="wrap_content" />

 <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

1 Ответ

0 голосов
/ 17 февраля 2012

В моем случае есть один "хак".

Я помещаю галерею в еще один LinearLayout, делаю его WrapContent по умолчанию и Gallery FitParent, когда я нажимаю кнопку «еще», я увеличиваю высоту макета (предыдущая высота + количество строк нового текстового представления * sizeoftext).

...