使用GridView和LinearLayout,Gridview在顶部显示

时间:2016-02-11 05:17:59

标签: java android xml android-layout gridview

我正在设计布局如下。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
<ScrollView 
    <LinearLayout
        <LinearLayout
            <TextViewなど
            .
            .
            .
        </LinearLayout>
        <LinearLayout
            <packagename.ExpandableHeightGridView
        </LinearLayout>
    </LinearLayout>
</ScrollView>

我在nexus5上执行程序。 如下所示,Gridview在顶部显示。

enter image description here

如果我滚动到顶部,则表示LinearLayout。

enter image description here

我试图调整布局。 但GridView没有调整。 我想先将LinearLayout设置为顶部。

public class Activity_CommunicationSpace_MemberList extends Activity {

private List<Data_User> objects = new ArrayList<Data_User>();
private Data_User item = new Data_User();
private String user_name;
private Bitmap user_icon;
private Bitmap user_profile;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_communicationspace_memberlist);

    user_name = "Test_Test";
    user_icon = BitmapFactory.decodeResource(getResources(), R.drawable.icon_lamborghini);

    for (int i = 0; i < 60; i++) {
        item = new Data_User();
        item.setNameData(user_name);
        item.setIconData(user_icon);
        objects.add(item);
    }

    Adapter_CommunicationSpace_MemberList adapter = new Adapter_CommunicationSpace_MemberList(getApplicationContext(), R.layout.adapter_communicationspace_memberlist, objects);
    ExpandableHeightGridView expandableHeightGridView = (ExpandableHeightGridView) findViewById(R.id.gridview_communicationspace_memberlist);
    expandableHeightGridView.setExpanded(true);
    expandableHeightGridView.setAdapter(adapter);

    final ScrollView scrollView = (ScrollView) findViewById(R.id.activity_communicationspace_memberlist_scrollView);
    scrollView.post(new Runnable() {
        public void run() {
            scrollView.fullScroll(ScrollView.FOCUS_UP);
        }
    });
}

1 个答案:

答案 0 :(得分:0)

如果Listview和Gridview在底部,那么它的Scroll本身。在这种情况下,他们不需要Scrollview或ExpendeableGridview 你应该尝试这种布局

00:A0:50:([A-Fa-f0-9]{2}:){2}[A-Fa-f0-9]