Android ScrollView不显示热门内容

时间:2016-12-15 20:52:39

标签: android scrollview

我有问题,其中android scrollview开始隐藏一对textview(Top~5-6行没有显示)。我使用填充,边距,fillviewport,wrap in linearlayout,原始scrollview等许多变化,但它没有工作。我在api 16和23都检查了这个问题。

我工作了很多时间,但没有找到解决方案。

dialog_base.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/base"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

    <android.support.v7.widget.AppCompatImageView
            android:id="@+id/wallpaper"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignBottom="@+id/panelAlt"
            android:clickable="false"
            android:focusable="false"
            android:visibility="gone"/>

    <include
            layout="@layout/toolbar"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"/>

    <android.support.v7.widget.AppCompatTextView
            android:id="@+id/topInfo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="8dp"
            android:layout_below="@id/toolbar"/>

    <RelativeLayout
            android:id="@+id/innerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/topInfo">

        <!--Inner view-->

    </RelativeLayout>

    <LinearLayout
            android:id="@+id/lyBottom"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical|right"
            android:layout_below="@+id/innerView"
            android:animateLayoutChanges="true">

        <android.support.v7.widget.AppCompatButton
                android:id="@+id/b1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="?selectableItemBackground"/>

        <android.support.v7.widget.AppCompatButton
                android:id="@+id/b2"

                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

        <android.support.v7.widget.AppCompatButton
                android:id="@+id/b3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

    </LinearLayout>

</RelativeLayout>

dialog_checkbox.xml(此视图以编程方式膨胀,并在object_base.xml中添加id:innerView布局)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

    <include
            android:id="@+id/scroll"
            layout="@layout/scroll_and_text"/>

    <android.support.v7.widget.AppCompatCheckBox
            android:id="@+id/checkbox"
            android:layout_below="@+id/scroll"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"/>

</RelativeLayout>

scroll_and_text.xml

<?xml version="1.0" encoding="utf-8"?>
<app.CustomScrollView xmlns:android="http://schemas.android.com/apk/res/android"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:scrollbars="vertical"
                      android:fadeScrollbars="true"
                      android:scrollbarStyle="outsideInset"
                      android:scrollbarFadeDuration="3000"
                      android:fillViewport="true">

    <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical">

        <android.support.v7.widget.AppCompatImageView
                android:id="@+id/icon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:visibility="gone"
                android:layout_marginRight="16dp"/>

        <android.support.v7.widget.AppCompatTextView
                android:id="@+id/text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

    </LinearLayout>

</app.CustomScrollView>

CustomScrollView.java

public class CustomScrollView extends ScrollView {

    private final int maxHeight = Utils.dptoPx(250);

    public CustomScrollView(Context context) {
        super(context);
    }

    public CustomScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        try {
            int heightSize = MeasureSpec.getSize(heightMeasureSpec);
            if (maxHeight != -1 && heightSize > maxHeight) {
                heightSize = maxHeight;
            }

            heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.AT_MOST);
            getLayoutParams().height = heightSize;
        } catch (Exception e) {
            Log.print(e);
        } finally {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }

}

提前致谢!

0 个答案:

没有答案
相关问题