浏览 13672 次
锁定老帖子 主题:GridView 元素间距设定
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2010-05-10
GridView 元素距离设定
因为该设定比较简单 防止以后忘记 所以贴 供自己查阅
1. 布局:main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <GridView android:id="@+id/grid" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:horizontalSpacing="50dp" android:verticalSpacing="50dp" /> </RelativeLayout>
2. *.jave: GriUsage.java
public class GridUsage extends Activity { GridView grid; ImageAdapter iAdapter; String[] text = { "one","two","three","four","five","six","seven","eight","nine","ten" }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); grid = (GridView)findViewById(R.id.grid); iAdapter = new ImageAdapter(this); grid.setAdapter(iAdapter); grid.setNumColumns(3); } public class ImageAdapter extends BaseAdapter { Activity activity; public ImageAdapter(Activity a){ activity = a; } @Override public int getCount() { // TODO Auto-generated method stub return text.length; } @Override public Object getItem(int arg0) { // TODO Auto-generated method stub return null; } @Override public long getItemId(int arg0) { // TODO Auto-generated method stub return arg0; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub TextView tv; if(convertView == null){ tv = new TextView(activity); } else { tv = (TextView)convertView; } tv.setSingleLine(true); tv.setBackgroundResource(R.drawable.back); tv.setGravity(Gravity.CENTER); tv.setText(text[position]); return tv; } } }
3. emulator 运行截图:
that's all. any idea or other are welcome!!!!
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2010-07-09
你好,能给我解释一下资源文件中back.9.png的名字问题吗,去掉9就会有问题。麻烦你了
|
|
返回顶楼 | |
发表时间:2010-07-10
不能设置行高.让我很头疼
|
|
返回顶楼 | |
发表时间:2010-07-15
kaixuan_166 写道 你好,能给我解释一下资源文件中back.9.png的名字问题吗,去掉9就会有问题。麻烦你了
我来回答你吧,那个9是表示这张图片为了在缩放的时候不至于变形而处理过。9不能去掉 |
|
返回顶楼 | |