【发布时间】:2020-03-13 00:05:40
【问题描述】:
在我的 xml 文件中,我有一个线性布局,其中有一个 ViewPager 用于显示图像,另一个线性布局包含用于选择图像的上一个和下一个按钮。我的 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.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/goto_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="first" >
</Button>
<Button
android:id="@+id/goto_last"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="last" >
</Button>
</LinearLayout>
</LinearLayout>
我的问题是 ViewPager 正在全屏显示,并且带有上一个下一个按钮的 Linearlayout 没有显示,因为没有剩余空间来绘制此 LinearLayout。
我正在使用 Fragments 用视图填充 ViewPager。进入 ViewPager 的片段视图的 xml 文件是:
<ImageView
android:id="@+id/ItemImage"
android:layout_width="320dp"
android:layout_height="180dp" />
<TextView
android:id="@+id/ItemText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|bottom"
android:layout_marginBottom="5dp"
android:textColor="#ffffffff"
android:textStyle="bold" />
</FrameLayout>
渲染后我得到的输出是这样的:
1.image(覆盖45%屏幕高度)
2.空白空间(覆盖45%屏幕高度)
3.Textview(覆盖其余10%屏幕高度)
我想要的输出是:
1.image(覆盖45%的屏幕高度)
2.Textview(覆盖10%屏幕高度)
3.LinearLayout for Buttons(覆盖剩下的 45% 屏幕高度)
【问题讨论】:
-
我得到了答案 [link]stackoverflow.com/questions/8532307/…
-
那么你今天学到了什么?在问问题之前先在这个网站上进行一些谷歌搜索和搜索:)
-
@Miral 我做到了,但不知何故它没有出现在搜索结果中,突然在发布这个问题后我找到了问题的链接。无论如何,从下次开始我会花更多时间搜索跨度>
-
我认为你的问题是由于 android:layout_gravity="left|bottom"
-
@Sherya 不,这不是问题,因为我删除了它但仍然得到相同的结果。我要为我的问题添加答案。等待几秒钟
标签: android android-layout android-viewpager