开发者

Android: Instantiating Multiple Widgets From One Layout Declaration

I am creating a custom widget to display a rotating list of items. I have declared the layout in newsview.xml:

<?xml version="1.0" encoding="utf-8"?>    
<RelativeLayout
            android:id="@+id/tblLink"
            style="@style/newsviewstyle"
            android:layout_alignParentBottom="true">

            <ImageView
                android:id="@+id/newsviewimg"
                style="@style/newsviewimgstyle"
                android:layout_margin="5dp" />

            <TextView 
                android:id="@+id/newsviewtitle"
                android:layout_toRightOf="@id/newsviewimg"
                android:layout_marginTop="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginBottom="5dp"
                android:layout_width="fill_parent"
                android:layout_height="50dp"
                android:textColor="#000000" />
            <TextView 
                android:id="@+id/newsviewurl"
                android:layout_toRightOf="@id/newsviewimg"
                android:layout_below="@id/newsviewtitle"
                android:layout_marginTop="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginBottom="5dp"
                android:layout_width="fill_parent"
                android:layout_height="15dp"
                android:textColor="#000000" />
        </RelativeLayout>

The idea is in my main.xml, I have a ViewFlipper that I would like to use animate the transitions between each item. How could I instantiate "n" unique items declared above, so they can bee added to the ViewFlipper. How would I be able to get access to the layout declared from a class outside the main activity (and also outside the package containing the main application, i.e. a view controller).

As a note, collecting the list of items takes place in a co开发者_StackOverflow中文版ntroller outside the main activity of my application. I would like to keep everything as much as possible in the controller for possible reuse later on.


How could I instantiate "n" unique items declared above, so they can bee added to the ViewFlipper.

Use getLayoutInflater().inflate(), the same way you would in a custom Adapter. In fact, on Honeycomb, there is AdapterViewFlipper to handle this very scenario.

How would I be able to get access to the layout declared from a class outside the main activity (and also outside the package containing the main application, i.e. a view controller).

I'm sorry, but this sentence did not parse for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜