views:

87

answers:

1

I have a list view which uses a custom adapter in order to show my custom content. Its layout is the following.

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1">
        <ImageView
            android:id="@+id/itemimage"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="5"
            android:scaleType="fitCenter"/>
        <TextView
            android:id="@+id/itemdescription"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="10dp"
            android:textSize="16sp"
            android:layout_weight="1"/>
    </LinearLayout>    
    <TextView
            android:id="@+id/itemtext"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="TEXT CONTENT"
            android:layout_weight="1"/>
</LinearLayout>    

I would like that the listview only showed the view with the ids itemimage and item description, keeping the itemtext hidden. The idea is to have an onclicklistener on each item of the list, in order to expand that item so it shows the itemtext content. I know I should use Tweening animation in order to expand/collapse each item, but I can't figure out how to do that.

Can anyone help me with it? If you need more code snippets, feel free to ask.

Thanks in advance.

A: 

Simple approach would be to use android.view.View.setVisibility() functionality. Namely, you can do the following:

  • use ScrollView as a root of your layout. Then put LinearLayout as achild. In that LinearLayout put item then description below, the again item and description ... This may span several screens length.

  • In the layout specify that all descriptions are hiden (and occupy no space) by setting Visible property to GONE value.

  • in your program set on click listener for each item . When item selected make description visible by (itemdescriptionID is e.g. TextView ID in your layout)

    itemdescriptionID.setVisibility(View.VISIBLE)

  • you may also implement toggle functionality, so click on item with opened description causes again making description gone via

    itemdescriptionID.setVisibility(View.GONE)

Desiderio
But that wouldn't allow me to apply an animation to expand and collapse the description smoothly. The idea is that when you click, the description becomes visible with an animation (like sliding down to show and back up to hide)
MIL3S
Then please use TextSwitcher element and check example in your Android SDK dir: android-sdk-windows\samples\android-8\ApiDemos\src\com\example\android\apis\view\TextSwitcher1.java
Desiderio