在视图寻呼机制作的图像中放置按钮?
put buttons in images made by view pager?
我用 ViewPager 和 Picasso 制作了一个图像滑块。而且,我在 java 中做了 next,prev,但是我在将这些按钮放在 ImageView 的底部时遇到了麻烦。
可以看到按钮,但它们不是重叠图像,而是分开的。
XML activity 的代码,其中我使用 ViewPager
显示了图像滑块
<?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>
试试这个希望它适合你
<?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>
<RelativeLayout
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"/>
</RelativeLayout>
此 属性 仅适用于 Relativelayout
android:layout_alignParentBottom="true"
我用 ViewPager 和 Picasso 制作了一个图像滑块。而且,我在 java 中做了 next,prev,但是我在将这些按钮放在 ImageView 的底部时遇到了麻烦。
可以看到按钮,但它们不是重叠图像,而是分开的。
XML activity 的代码,其中我使用 ViewPager
显示了图像滑块<?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>
试试这个希望它适合你
<?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>
<RelativeLayout
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"/>
</RelativeLayout>
此 属性 仅适用于 Relativelayout
android:layout_alignParentBottom="true"