开发者

Set a ViewFlipper weight programmatically

I'd like to change weight of a ViewFlipper programmatically. I have a TableRow in which I have 2 columns. The first column contains a RelativeLay开发者_开发知识库out element when the second column contains a ViewFlipper. My ViewFlipper contains 2 views. Somehow in my Java code, I change the visible view of my ViewFlipper when I click on a button. What I want to do is to be able, when I change the ViewFlipper view (by calling showNext()), to change the ViewFlipper weight in order for it to be larger in the screen.

In other words, the first column of my row has a weight=1 and the second (the ViewFlipper) has a weight=0.8. When I click on a button I want to change those weights programmatically. Is that possible ? How ? Below is my XML code.

I've searched on the Web, I found this solution:

myFlipper.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0.3f));

This doesn't work, it crashes, which is, I think normal as the ViewFlipper isn't a LinearLayout.

Here is my XML code:

    <TableRow
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="#00000000" >
    <RelativeLayout
        android:id="@+id/rltest"
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:layout_centerInParent="true"
        android:paddingLeft="6px"
        android:paddingRight="6px"
        android:background="#00000000" >
        <TextView
            android:id="@+id/tvtest"
            android:layout_width="match_parent"
            android:layout_height="60px"
            android:layout_alignParentLeft="true"
            android:textColor="#FFFFFF"
            android:textSize="22px"
            android:singleLine="true"
            android:background="#00000000"
            android:gravity="center_vertical" />
    </RelativeLayout>
    <ViewFlipper
        android:id="@+id/flipper"
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="0.8"
        android:background="#00000000" >
        <TextView
            android:id="@+id/tvName"
            android:layout_width="wrap_content"
            android:layout_height="60px" />
        <LinearLayout
            android:id="@+id/lltest"
            android:layout_width="match_parent"
            android:layout_height="60px"
            android:layout_centerInParent="true"
            android:background="#00000000"
            android:gravity="center" />
    </ViewFlipper>
</TableRow>

Do you have any idea ?

Thanks


My guess: you should be using TableRow.LayoutParams, not LinearLayout.LayoutParams. But that's just a guess without seeing the actual error; any time you ask a question about a crash on SO you should really include the log with the traceback of your error.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜