<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context="com.lin.mr.mystudy.scrollview.TestActivity">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
public class TestActivity extends Activity {
private ListView listView;
private ArrayList<String> list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
listView = (ListView) findViewById(R.id.listView);
findViewById(R.id.ll_container);
list = new ArrayList<>();
//生成需要显示到ListView中的数据
for (int i = 0; i < 30; i++) {
list.add("这是数据"+i);
}
//使用ArrayAdapter适配数据
listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,list));
}
}
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="com.lin.mr.mystudy.scrollview.TestActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="按钮一" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="按钮二" />
</LinearLayout>
</ScrollView>
/**
* 自定义ListView
*/
public class MyListView extends ListView {
public MyListView(Context context) {
super(context);
}
public MyListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
heightMeasureSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE>>2,//右移运算符,相当于除于4
MeasureSpec.AT_MOST);//测量模式取最大值
super.onMeasure(widthMeasureSpec,heightMeasureSpec);//重新测量高度
}
}
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="com.lin.mr.mystudy.scrollview.TestActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
<com.lin.mr.mystudy.scrollview.MyListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.lin.mr.mystudy.scrollview.MyListView>
<Button
android:layout_margin="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="按钮一" />
<Button
android:layout_margin="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="按钮二" />
</LinearLayout>
</ScrollView>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有