【发布时间】:2014-07-07 13:03:24
【问题描述】:
朋友们,
我是 android 新手,所以我可以使用您的帮助。我想实现一个用户可以在两个图像之间翻转的画廊(在下面的 ImageView1 中呈现)。我想要的显示由:
[TextView1] [TextView2]
[ImageView1]
[ImageView2]
其中 [TextView1] 和 [TextView2] 是静态文本,不会随着两个图像之间的翻转而改变。 [ImageView1] 是实际显示的图像,[ImageView2] 是图像指示符(即选择图像之一)。
我正在使用 ViewPager 将图像绑定到 [ImageView1],如下所示:
<?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="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<ImageView
android:id="@+id/image_to_show"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:contentDescription="@string/image_description"
android:scaleType="fitCenter" />
</RelativeLayout>
显示图像的主要片段:
<?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="wrap_content" >
<TextView
android:id="@+id/name_of_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:textColor="@color/card_text_color"
android:textSize="14sp" />
<TextView
android:id="@+id/date_taken"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingBottom="10dp"
android:textColor="@color/card_text_color"
android:textSize="14sp" />
<android.support.v4.view.ViewPager
android:id="@+id/details_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="10dp" />
<LinearLayout
android:id="@+id/page_indicator_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"/>
</RelativeLayout>
代码的输出是:
[TextView1] [TextView2]
[ImageView2]
[ImageView1]
图像和页面指示器的位置相反。
有什么办法可以解决这个问题吗?
我不希望视图之间有任何垂直空间。我使用LinearLayout 而不是RelativeLayout 作为主要片段,但这会根据屏幕大小在视图之间留出空间。
【问题讨论】:
标签: android android-layout android-fragments android-relativelayout