0

I have a layout xml file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:background="#000000" >
    <FrameLayout
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:layout_above="@+id/taoFooter">
        <com.example.gamedice.DrawingPanel
            android:id="@+id/taoCanvas"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:background="#000000" />
    </FrameLayout>
    <LinearLayout
        android:id="@+id/taoFooter"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        style="@android:style/Holo.ButtonBar">
        <Button
            android:id="@+id/roll1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="@string/roll1"
            android:layout_weight="1" 
            style="@android:style/Widget.Holo.Button.Borderless"
            android:onClick="rollTaoDice" />
        <Button
            android:id="@+id/roll2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="@string/roll2" 
            android:layout_weight="1"
            style="@android:style/Widget.Holo.Button.Borderless"
            android:onClick="rollTaoDice" />
        <Button
            android:id="@+id/roll3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="@string/roll3"
            android:layout_weight="1"
            style="@android:style/Widget.Holo.Button.Borderless"
            android:onClick="rollTaoDice" />
        <Button
            android:id="@+id/roll4"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="@string/roll4" 
            android:layout_weight="1"
            style="@android:style/Widget.Holo.Button.Borderless"
            android:onClick="rollTaoDice" />
        </LinearLayout>
</RelativeLayout>

In addition to other items in the layout, this layout has a button bar consisting of four buttons at the bottom of the screen. Based on user input, I want to be able to replace this button bar with another predefined set of buttons, and then be able to change back later.

Since I know what the alternate set of buttons will be ahead of time, I thought it might be possible to use an alternate layout xml file, but I couldn't figure out how to do that. Can anyone give me some guidance?

4

1 回答 1

1

您可以像使用第一组一样在布局中添加第二组按钮,然后在布局 xml 文件中设置android:visibility="gone"第二个布局的属性。在您的代码中,您可以在需要切换按钮时调用setVisibility(View.GONE)一种布局(例如taoFooter)和另一种布局。setVisibility(View.VISIBLE)

或者,如果您想轻松添加一些动画,您可以在两个备用按钮布局周围添加一个ViewFlipper 。默认情况下只有第一个可见。您可以使用 切换到下一个布局showNext()setInAnimation()在此之前和setOutAnimation()之前添加调用以启用动画。

于 2013-07-05T14:47:06.683 回答