android - 显示位于列表底部

标签 android gridview

在 Nexus S 和 WildFire 上,当显示我的 ExpandableHeightGridView 时,activity View 默认位于 scrollview 的底部。 当我启动应用程序时,ExpandableHeightGridView 具有不同的 View ,然后主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>

最佳答案

尝试将 ScrollView 设置为不可聚焦。我遇到了同样的问题,这解决了它。

yourExpandableHeightGridView.setFocusable(false);

android:focusable="false"

XML 格式。

关于android - 显示位于列表底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14998819/

相关文章:

Android 2.2 + SQLite + 定义参照完整性约束

java - 如何使用卡片向 RecyclerView 添加 searchBar

java - 在 Android 上使用客户端/服务器证书进行双向身份验证 SSL 套接字

javascript - 获取 Gridview 选中项目的列表

c# - 通过 ObjectDataSource : Why is maximumRows being set to -1? 的 Gridview 分页

android - 在不删除旧数据的情况下向 FTP 服务器中的文件添加内容?

java - 如何隐藏 android studio 编辑器中的导航栏?

c# - 格式化 DataTable 列的百分比

c# - 我可以根据发件人( GridView )使用特定代码将两个 GridView 绑定(bind)到一个数据源吗?

Android - 用于交错 GridView 的 OnScrollListener