![](/img/trans.png)
[英]How to add gif image in the background of view pager android studio?
[英]How to add button to a view pager in Android Studio?
我想向“查看尋呼機”添加按鈕。 嘗試添加按鈕,片段和布局失敗。 我也嘗試過這樣: 向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:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.airpal.yonatan.airpal.MainActivity_User">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/appBarLayout">
<include layout="@layout/app_bar_layout" android:id="@+id/main_page_toolbar" />
<android.support.design.widget.TabLayout
android:id="@+id/main_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabSelectedTextColor="@android:color/white"
app:tabTextColor="@android:color/white">
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/main_tabPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/appBarLayout">
</android.support.v4.view.ViewPager>
</LinearLayout>
這是屏幕截圖,我想在頁面底部添加按鈕。 謝謝。
嘗試對根視圖使用RelativeLayout並使用:
android:layout_alignParentBottom="true"
在根視圖中無法使用LinearLayout。 另外,ConstraintLayout代替RelativeLayout是一個很好的選擇。
您可以在相對布局中包裝此LinearLayout。 如果您不想將線性布局更改為RelativeLayout。 這是修改后的布局XML,它將在右下角顯示Button。 您可以向左修改layout_alignParentRight,居中取決於您的需要。
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.airpal.yonatan.airpal.MainActivity_User">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/appBarLayout">
<include layout="@layout/app_bar_layout" android:id="@+id/main_page_toolbar" />
<android.support.design.widget.TabLayout
android:id="@+id/main_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabSelectedTextColor="@android:color/white"
app:tabTextColor="@android:color/white">
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/main_tabPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/appBarLayout">
</android.support.v4.view.ViewPager>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.