Layout_height不想在使用片段时逐渐包装内容

时间:2017-12-12 12:45:43

标签: android css xml android-layout android-fragments

我想要完成的是创建评级部分,如Google Play Store,我设法显示所有的星星并审查(供用户评论),但每当用户在其上键入时,RelativeLayout的布局高度我的活动并没有在片段中包装片段的布局。我尝试以任何方式改变高度,但仍然没有解决问题。问题是,当我TabLayout可见时,它跟随高度,但不是我的custom ViewPager

我不知道我是做对还是错或完全不可能,请告诉我正确的方法。谢谢。

activity_view_item.xml

<?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:layout_height="match_parent"
tools:context="com.hybridelements.recyclerview.ViewItem">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentLeft="true">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/singleImageView"
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="29dp"
            app:srcCompat="@drawable/android" />

        <TextView
            android:id="@+id/lblTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/lblTitle"
            android:layout_alignBottom="@+id/itemName"
            android:textSize="16sp"
            android:layout_marginLeft="25dp"
            android:textStyle="bold"/>

        <TextView
            android:id="@+id/itemName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:text="@string/itemName"
            android:textSize="16sp"
            android:layout_below="@+id/singleImageView"
            android:layout_alignStart="@+id/singleImageView"/>



        <TextView
            android:id="@+id/lblCategory"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/lblCategory"
            android:layout_alignTop="@+id/itemCategory"
            android:layout_alignStart="@+id/lblTitle"
            android:layout_marginRight="30dp"
            android:textSize="16sp"
            android:textStyle="bold"/>

        <TextView
            android:id="@+id/itemCategory"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/itemCategory"
            android:textSize="16sp"
            android:layout_below="@+id/itemName"
            android:layout_alignStart="@+id/singleImageView"
            android:layout_marginTop="14dp" />

        <TextView
            android:id="@+id/lblRating"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignStart="@+id/lblCategory"
            android:layout_below="@+id/lblCategory"
            android:layout_marginTop="13dp"
            android:text="@string/lblRating"
            android:textSize="16sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/itemRating"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/lblRating"
            android:layout_alignStart="@+id/singleImageView"
            android:text="@string/itemRating"
            android:textSize="16sp" />

        <ImageView
            android:id="@+id/imageRating"
            android:layout_width="17dp"
            android:layout_height="17dp"
            android:layout_alignBottom="@+id/itemRating"
            android:layout_alignTop="@+id/itemRating"
            android:layout_gravity="center"
            android:layout_toEndOf="@+id/itemRating"
            android:layout_marginLeft="5dp"
            app:srcCompat="@drawable/star" />

        <TextView
            android:id="@+id/lblDesc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="13dp"
            android:text="@string/lblDesc"
            android:textSize="16sp"
            android:textStyle="bold"
            android:layout_alignStart="@+id/itemDesc"
            android:layout_below="@+id/itemRating"/>

        <TextView
            android:id="@+id/itemDesc"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/lblDesc"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:layout_marginTop="13dp"
            android:text="@string/itemDesc"
            android:textSize="16sp" />

        <RelativeLayout
            android:id="@+id/ratingSection"
            android:layout_width="match_parent"
            android:layout_height="130dp"
            android:layout_marginTop="13dp"
            android:layout_below="@+id/itemDesc"
            android:background="@color/ratingSection">

            <!-- Get section from fragment -->

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/subTab"
            android:layout_width="match_parent"
            android:layout_height="511.84dp"
            android:layout_marginTop="13dp"
            android:layout_below="@+id/ratingSection">

            <!-- Get section from fragment -->

        </RelativeLayout>

    </RelativeLayout>

</ScrollView>

fragment_sub_section_rating.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.hybridelements.openchef.fragment_activities.fragment_subs.SubSectionFragment_ReviewAndInstructions">

<RelativeLayout
    android:id="@+id/main_layout"
    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="wrap_content"
    tools:context=".MainActivity">

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:elevation="6dp"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:visibility="gone"/>

    <com.hybridelements.openchef.fragment_activities.fragment_subs.CustomSubViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/tab_layout"/>

    <com.pixelcan.inkpageindicator.InkPageIndicator
        android:id="@+id/fragRating_dotIndicator"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:dotDiameter="8dp"
        app:dotGap="8dp"
        app:animationDuration="320"
        app:pageIndicatorColor="@android:color/darker_gray"
        app:currentPageIndicatorColor="@android:color/black"
        android:layout_alignBottom="@+id/pager"
        android:layout_marginBottom="20dp"
        android:visibility="gone" />

</RelativeLayout>

fragment_rating_review.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.hybridelements.openchef.fragment_activities.fragment_subs.RatingFragment_Star">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/ratingReview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/fragmentRating_reviewHeader"
        android:textAlignment="center"
        android:layout_marginTop="13dp"
        android:textSize="16dp"
        android:textStyle="bold" />

    <RelativeLayout
        android:id="@+id/ratingStar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ratingReview"
        android:gravity="center_horizontal">

        <EditText
            android:id="@+id/userRateReview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"/>

    </RelativeLayout>

    <Button
        android:id="@+id/ratingBtnSubmit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ratingStar"
        android:layout_alignParentEnd="true"
        android:text="@string/ratingFrag_BtnSubmit"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:enabled="false"/>


</RelativeLayout>

RelativeLayout with id "ratingSection" in ratingSactivity_view_item.xml应遵循height of FrameLayout in fragment_rating_review.xml

这不应该发生。

This is before any typing (seems normal)

After typing, the submit button going off the screen

1 个答案:

答案 0 :(得分:0)

尝试使用此布局。

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/ratingReview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="fragmentRating_reviewHeader"
        android:textAlignment="center"
        android:layout_marginTop="13dp"
        android:textSize="16dp"
        android:textStyle="bold" />

    <RelativeLayout
        android:id="@+id/ratingStar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/ratingStar"
        android:layout_below="@+id/ratingReview"
        android:gravity="center_horizontal">

        <EditText
            android:id="@+id/userRateReview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"/>

    </RelativeLayout>

    <Button
        android:id="@+id/ratingBtnSubmit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/ratingStar"
        android:text="ratingFrag_BtnSubmit"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:enabled="false"/>


</LinearLayout>
</FrameLayout>