android - 在视图寻呼机制作的图像中放置按钮?
问题描述
我用 ViewPager 和 Picasso 制作了一个图像滑块。而且,我也做了下一个,在java中的prev,但是在将这些按钮放在ImageView的底部时我遇到了麻烦。
可以看到按钮,但它们不是重叠的图像,而是分开的。
我使用 ViewPager 显示图像滑块的 XML 活动代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:id="@+id/btn_next"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Previous"
android:id="@+id/btn_previous"/>
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.recyclerview_codelabs.MainActivity">
</android.support.v4.view.ViewPager>
</LinearLayout>
解决方案
Use this, it will work fine.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.recyclerview_codelabs.MainActivity">
</android.support.v4.view.ViewPager>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:id="@+id/btn_next"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Previous"
android:id="@+id/btn_previous"/>
</LinearLayout>
</RelativeLayout>
推荐阅读
- javascript - Javascript,将我的字符串作为参数传递将其变为 0
- java - 使用 JDK 11 在 Mac 上打开 .jar 文件失败并出现 RuntimeException
- python - 通过类内的 For 循环使用 linspace 进行迭代
- javascript - 没有得到 Angular 控制器的响应
- c++ - 某些 C++ 类的代码会意外覆盖另一个类的私有静态变量吗?
- javascript - 如何将 javascript + jquery 转换为统一 csharp?
- ios - Swift:从 _PFEncodedString 转换为 String(使用 JSONEncoder 导出核心数据属性)
- python - Python argparser 无法识别
- c - 为什么添加 send() 调用会使之前的 send() 调用失败?
- php - 在 WooCommerce 管理员订单列表中添加自定义订单状态以过滤菜单