滚动视图的最后一项是隐藏的,当展开时,它不可见

时间:2016-01-21 13:01:19

标签: android android-layout android-scrollview

我有ScrollView喜欢:

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

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

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

            <ImageView
                android:id="@+id/place_image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@mipmap/tourist_place_details" />

            <ImageView
                android:id="@+id/images"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:layout_margin="20dp"
                android:src="@mipmap/ic_imagegallery" />
        </FrameLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:minWidth="30dp"
                android:layout_gravity="center_vertical"
                android:src="@mipmap/icon_clock" />

            <TextView
                android:id="@+id/txt_time"
                style="@android:style/TextAppearance.Medium"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:layout_marginLeft="10dp"
                android:text="9:00am - 6:00pm"
                android:textColor="@color/gray_categories" />

        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@color/divider" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:minWidth="30dp"
                android:layout_gravity="center_vertical"
                android:src="@mipmap/icon_fare" />

            <TextView
                android:id="@+id/txt_fare"
                style="@android:style/TextAppearance.Medium"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:layout_marginLeft="10dp"
                android:ellipsize="end"
                android:maxLines="1"
                android:text="Adult 10/-  Child 5/-  Tourist 100/-"
                android:textColor="@color/gray_categories" />

        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@color/divider" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:minWidth="30dp"
                android:layout_gravity="center_vertical"
                android:src="@mipmap/ic_location" />

            <TextView
                android:id="@+id/txt_address"
                style="@android:style/TextAppearance.Medium"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:layout_marginLeft="10dp"
                android:ellipsize="end"
                android:maxLines="2"
                android:text="blah balh blah"
                android:textColor="@color/gray_categories" />

        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@color/divider" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:minWidth="30dp"
                android:layout_gravity="center_vertical"
                android:src="@mipmap/icon_call" />

            <TextView
                android:id="@+id/txt_contact_numbers"
                style="@android:style/TextAppearance.Medium"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:layout_marginLeft="10dp"
                android:ellipsize="end"
                android:maxLines="1"
                android:text="+1 999999999999"
                android:textColor="@color/gray_categories" />

        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@color/divider" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_margin="10dp"
            android:background="@mipmap/image_map"
            android:orientation="vertical">


        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@color/divider" />



        <TextView
            android:id="@+id/txt_about"
            style="@android:style/TextAppearance.Medium"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:paddingLeft="5dp"
            android:text="@string/about"
            android:textColor="@color/gray_categories" />

        <TextView
            android:id="@+id/txt_desc"
            style="@android:style/TextAppearance.Small"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:paddingLeft="5dp"
            android:layout_marginRight="10dp"
            android:ellipsize="end"
    android:visibility="gone"
            android:maxLines="5"
            android:text="asdkjsadkja adslkgsadkjbsakd asdkjsadkja aldsgsakjdbdlkashdkjsabhdk lashdlksajd asdhkj asdkj askjd asjhd lakjhsbd asdkjsadkja adslkgsadkjbsakd aldsgsakjdbdlkashdkjsabhdk lashdlksajd asdhkj asdkj askjd asjhd lakjhsbd "
            android:textColor="@color/gray_categories" />

    </LinearLayout>
</ScrollView>

&#34;关于&#34; TextView可见,隐藏txt_desc。 单击“关于”,然后使用以下方法向下滑动使txt_desc可见:

public static void expand(final View v) {
    v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    final int targetHeight = v.getMeasuredHeight();

    // Older versions of android (pre API 21) cancel animations for views
    // with a height of 0.
    v.getLayoutParams().height = 1;
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime,
                                           Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1 ? LayoutParams.WRAP_CONTENT
                    : (int) (targetHeight * interpolatedTime);
            v.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int) (targetHeight / v.getContext().getResources()
            .getDisplayMetrics().density));
    v.startAnimation(a);
}

TextView txt_desc正在扩展但不可见,因为ScrollView停留在约txt_desc内容txt_desc内容未显示。如果我们滚动,则内容可见。

任何人都可以帮助scrollView.fullScroll(View.FOCUS_DOWN);在看到= simple_form_for current_user.posts.build do |f| 后可见。

我已经使用过= simple_form_for @post do |f| ,但没有使用

2 个答案:

答案 0 :(得分:2)

layout_height的{​​{1}}设为ScrollView,将match_parent设为paddingBottom

希望这有帮助。

答案 1 :(得分:0)

不要在 ScrollView 或 NestedScrollView 中使用填充

ScrollView 只能容纳一个孩子。在其子项中放置边距或内边距。