簡體   English   中英

Android-在片段中退出屏幕

[英]Android - Button out of the screen in Fragment

我僅通過一項活動就更改了我的Android應用程序,並開始使用帶有TabLayout的片段,但是底部的按鈕現在不在屏幕上。 我已經嘗試刪除app:layout_scrollFlags="scroll|enterAlways" ,更改為enterAlways ,還嘗試使用android:layout_below

這是我的片段:

<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.jovensprofissionais.breakfastitismytreat.fragments.PersonFragment">
<TextView
    android:id="@+id/personOfTheNextWeekTitle"
    android:layout_toStartOf="@+id/personOfTheNextWeek"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/person_of_the_next_week_title" />

<TextView
    android:id="@+id/personOfTheNextWeek"
    android:layout_alignParentEnd="true"
    android:layout_alignParentTop="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/person_of_the_next_week" />

<TextView
    android:id="@+id/personOfTheWeekTitle"
    android:textSize="25sp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/person_of_the_week_title"
    android:layout_above="@+id/personOfTheWeek"
    android:layout_centerHorizontal="true" />

<TextView
    android:id="@+id/personOfTheWeek"
    android:textSize="45sp"
    android:textColor="@color/colorPrimary"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/person_of_the_week" />

<RatingBar
    android:id="@+id/ratingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numStars="5"
    android:stepSize="1.0"
    android:layout_above="@+id/voteButton"
    android:layout_centerHorizontal="true"
    android:theme="@style/RatingBar"/>

<Button android:id="@+id/voteButton"
    android:text="@string/text_to_button_view"
    android:textColor="@color/colorPrimaryDark"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorAccent"
    android:gravity="center"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" />

這是我的activity_main

<android.support.design.widget.CoordinatorLayout 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">
<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:layout_scrollFlags="scroll|enterAlways"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabMode="fixed"
    app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

將整個Layout包裝在ScrollView中,該問題應該得到解決。

    <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            tools:context="com.jovensprofissionais.breakfastitismytreat.fragments.PersonFragment">

        <RelativeLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:paddingBottom="@dimen/activity_vertical_margin"
         android:paddingLeft="@dimen/activity_horizontal_margin"
         android:paddingRight="@dimen/activity_horizontal_margin"
         android:paddingTop="@dimen/activity_vertical_margin">
        <TextView
            android:id="@+id/personOfTheNextWeekTitle"
            android:layout_toStartOf="@+id/personOfTheNextWeek"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/person_of_the_next_week_title" />

        <TextView
            android:id="@+id/personOfTheNextWeek"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/person_of_the_next_week" />

        <TextView
            android:id="@+id/personOfTheWeekTitle"
            android:textSize="25sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/person_of_the_week_title"
            android:layout_above="@+id/personOfTheWeek"
            android:layout_centerHorizontal="true" />

        <TextView
            android:id="@+id/personOfTheWeek"
            android:textSize="45sp"
            android:textColor="@color/colorPrimary"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/person_of_the_week" />

        <RatingBar
            android:id="@+id/ratingBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:numStars="5"
            android:stepSize="1.0"
            android:layout_above="@+id/voteButton"
            android:layout_centerHorizontal="true"
            android:theme="@style/RatingBar"/>

        <Button android:id="@+id/voteButton"
            android:text="@string/text_to_button_view"
            android:textColor="@color/colorPrimaryDark"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent"
            android:gravity="center"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true" />
    </ScrollView>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM