下午好,今天我想在滚动视图中滚动一个网格视图。大概是这样的:scrollview中有LinearLayout,然后我在LinearLayout中插入了一个GridView。问题 gridView 仅显示一项。
我的xml:
<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" >
<ScrollView
android:id="@+id/record_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dip">
<LinearLayout
android:id="@+id/record_Layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</RelativeLayout>
我的java代码:
public class MainActivity extends Activity {
private LinearLayout linearLayout = null;
private ScrollView scrollView =null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
linearLayout = (LinearLayout)findViewById(R.id.record_Layout);
scrollView = (ScrollView)findViewById(R.id.record_scrollview);
GridView gd = new GridView(this);
List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("name", "huangli1");
list.add(map);
map = new HashMap<String, String>();
map.put("name", "huangli2");
list.add(map);
map = new HashMap<String, String>();
map.put("name", "huangli3");
list.add(map);
SimpleAdapter simpleAdapter = new SimpleAdapter(this, list, R.layout.list_item, new String[]{"name"}, new int[]{R.id.tv}){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
return super.getView(position, convertView, parent);
}
};
gd.setAdapter(simpleAdapter);
linearLayout.addView(gd);
}