自定义ListView
来源:互联网 发布:智能化数据分析 编辑:程序博客网 时间:2024/06/05 08:57
自定义ListView部分:
package com.example.day10_;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;
public class MyListView extends ListView{
public MyListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MyListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyListView(Context context) {
super(context);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
heightMeasureSpec=
MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE>>2,//扩展高度的最大值
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
xml文件中引入自定义的ListView:
<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=".MainActivity"
android:id="@+id/scrollView" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageViewId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@drawable/picture1" />
<com.example.day10_.MyListView
android:id="@+id/listid"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>
MainActivity中将其显示:
package com.example.day10_;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.ScrollView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
List<String> list=new ArrayList<String>();
for(char c='A';c<='Z';c++){
list.add(String.valueOf(c));
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lsv=(ListView) findViewById(R.id.listid);
lsv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,list));
ScrollView sc=(ScrollView) findViewById(R.id.scrollView);
sc.smoothScrollBy(0, 0); //平滑滚动到顶端
}
}
- 自定义 ListView
- 自定义ListView
- 自定义listview
- 自定义LISTVIEW
- 自定义ListView
- 自定义listview
- 自定义listview
- 自定义ListView
- 自定义ListView
- 自定义listview
- 自定义listview
- 自定义listview
- ListView-自定义
- ListView自定义
- 自定义ListView
- 自定义listView
- 自定义ListView
- 自定义ListView
- 包装流和缓冲流
- Linux进程通讯:消息队列
- 1062. Talent and Virtue (25)
- hdu5916 构造
- DTD 约束
- 自定义ListView
- Android Stuido下NDK的简单实现
- Windows线程同步机制的区别与比较及进程通信方法
- HDU 5914 Triangle【斐波那契数列】
- 图像二维离散傅里叶变换、幅度谱、相位谱
- [心得]面试题分析与整理2
- PHP代码规范
- Android多渠道打包(一):基础多渠道打包
- Java经典多线程问题--生产者与消费者