在Viewflipper上添加Textview

时间:2014-12-15 07:42:12

标签: android android-layout

我希望在Viewflipper slidshow中显示图像的描述。我需要在viewflipper幻灯片上添加textview或按钮。所以只有我可以显示基于textview的图像描述或按钮点击viewflipper这是我的xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:scaleType="fitXY" >

    <ViewFlipper
        android:id="@+id/myflipper"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:gravity="center"
        android:scaleType="fitXY" >
    </ViewFlipper>

</LinearLayout>

2 个答案:

答案 0 :(得分:0)

您可以使用FrameLayout将TextView放在ViewFlipper上,如下所示:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/tools"
    android:id="@+id/framelayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ViewFlipper
        android:id="@+id/myflipper"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:gravity="center"
        android:scaleType="fitXY" >
    </ViewFlipper>

    <TextView
        android:id="@+id/mytext"
        android:layout_width="match_parent"
        android:layout_height="30dp"/>

</FrameLayout>

查看this示例程序博客,了解有关如何使用FrameLayout的更多示例。

快乐编码:)

答案 1 :(得分:0)

您可以在Layout

中使用这种方式
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/KeepToolbar"
        android:orientation="vertical">

        <ViewFlipper
            android:id="@+id/viewflipper"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:autoStart="true"
            android:background="@color/ORANGE_700"
            android:inAnimation="@anim/right_in"
            android:outAnimation="@anim/left_out">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/a" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/a"
                        android:gravity="right"
                        android:layout_width="match_parent"
                        android:layout_height="30dp"
                        android:text="AAAA" />

                    <TextView
                        android:id="@+id/e"
                        android:gravity="right"
                        android:layout_width="match_parent"
                        android:layout_height="30dp"
                        android:text="asds" />

                    <TextView
                        android:id="@+id/w"
                        android:gravity="right"
                        android:layout_width="match_parent"
                        android:layout_height="30dp"
                        android:text="qweqw" />
                </LinearLayout>
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/b" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/b"
                        android:gravity="right"
                        android:layout_width="match_parent"
                        android:layout_height="30dp"
                        android:text="BBBB" />

                    <TextView
                        android:id="@+id/u"
                        android:gravity="right"
                        android:layout_width="match_parent"
                        android:layout_height="30dp"
                        android:text="ssd" />

                    <TextView
                        android:id="@+id/vb"
                        android:gravity="right"
                        android:layout_width="match_parent"
                        android:layout_height="30dp"
                        android:text="wwee" />
                </LinearLayout>
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/b" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/c"
                        android:gravity="right"
                        android:layout_width="match_parent"
                        android:layout_height="30dp"
                        android:text="CCCC" />

                    <TextView
                        android:id="@+id/cd"
                        android:gravity="right"
                        android:layout_width="match_parent"
                        android:layout_height="30dp"
                        android:text="asdfas" />

                    <TextView
                        android:id="@+id/cf"
                        android:gravity="right"
                        android:layout_width="match_parent"
                        android:layout_height="30dp"
                        android:text="xxs" />
                </LinearLayout>
            </LinearLayout>

        </ViewFlipper>