我正在开发一个Android应用程序,并且在一个屏幕布局中,我需要具有带有标题的gridview,但没有任何用于gridview的标题。所以我在instagram个人资料中看到他们像listview一样使用listview,但是我找不到任何东西,因此,如果有人知道做这种事情的另一种方法,我将不胜感激。
我想要这样的东西:
提前致谢
最佳答案
尝试以下代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<GridView
android:id="@+id/gridViewCustom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_alignParentRight="true"
android:layout_margin="4dp"
android:columnWidth="80dp"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" >
</GridView>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="THIS IS THE HEADER"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
在您的活动中:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.grid);
final TextView txt = (TextView) findViewById(R.id.textView1);
txt.setVisibility(View.VISIBLE);
GridView grid = (GridView) findViewById(R.id.gridViewCustom);
grid.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if(firstVisibleItem == 0)//or it is maybe 1 I'm not sure. It means you are at the top of the gridview
txt.setVisibility(View.VISIBLE);
else
txt.setVisibility(View.GONE);
}
});
}
关于android - 具有列和行的ListView Android,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25788865/