显示位于列表底部

时间:2013-02-21 09:36:35

标签: android gridview

在显示我的ExpandableHeightGridView时,在Nexus S和WildFire上,activity视图默认位于scrollview的底部。 当我启动应用程序时,ExpandableHeightGridView具有不同的视图,然后主layout自动滚动到底部! 有没有人遇到同样的问题?

这是我的ExpandableHeightGridView

public class ExpandableHeightGridView extends GridView {

    // Attributes
    private boolean mExpanded = true;

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

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

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

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        if (isExpanded()) {
            // Calculate entire height by providing a very large height hint.
            // But do not use the highest 2 bits of this integer; those are
            // reserved for the MeasureSpec mode.
            int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
            super.onMeasure(widthMeasureSpec, expandSpec);
            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = getMeasuredHeight();
        }
        else {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }

    public void setExpanded(boolean expanded) {
        mExpanded = expanded;
    }

    public boolean isExpanded() {
        return mExpanded;
    }
}

我的主要xml:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <RelativeLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="@dimen/program_showview_padding"
        android:paddingTop="@dimen/program_showview_padding_top">

        <TextView
            android:id="@+id/program_category"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/program_vignette"
            android:layout_alignParentRight="true" />
        <TextView
            android:id="@+id/program_sub_category"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/program_category"
            android:layout_toRightOf="@id/program_vignette"
            android:layout_alignParentRight="true" />
        <TextView
            android:id="@+id/program_duration"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/program_sub_category"
            android:layout_toRightOf="@id/program_vignette"
            android:layout_alignParentRight="true" />
        <ImageView
            android:id="@+id/program_csa"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/program_duration"
            android:layout_toRightOf="@id/program_vignette"/>
        <TextView
            android:id="@+id/program_tweets_count"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/program_csa"
            android:layout_toRightOf="@id/program_vignette"
            android:layout_alignParentRight="true" />
        <TextView
            android:id="@+id/program_summary_label"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/program_vignette"
            android:text="@string/program_showview_summary" />
        <TextView
            android:id="@+id/program_summary"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/program_summary_label" />
        <TextView
            android:id="@+id/program_casting_label"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/program_summary"
            android:text="fffffff" />
        <fr.haploid.widget.ExpandableHeightGridView
            android:id="@+id/program_casting"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/program_casting_label"
            android:numColumns="auto_fit" />
    </RelativeLayout>
</ScrollView>

1 个答案:

答案 0 :(得分:3)

尝试将您的滚动视图设置为无法对焦。我遇到了同样的问题,并修复了它。

yourExpandableHeightGridView.setFocusable(false);

android:focusable="false"
XML中的