我希望每个屏幕适合屏幕的每个项目/行。但是我在dp中为xml指定了高度和宽度来实现它。正弦我指定高度/宽度,每行不完全适合屏幕,也不适用于所有类型的屏幕分辨率。我将如何实现这一目标?有人可以就此提出想法吗?
以下是xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="schemas.android.com/apk/res/android"
android:layout_width="1024dip"
android:layout_height="480dip"
android:orientation="vertical" >
<TextView android:layout_width="1024dip"
android:layout_height="480dip"
android:text="ViewSwitcher"
android:textSize="20sp"
android:gravity="center"
android:padding="10dip"
android:background="#404040"
android:id="@+id/textView" />
</LinearLayout>
提前致谢。
答案 0 :(得分:1)
请利用线性布局,使用权重的特征,你可以将scren分辨率划分到任何程度......
答案 1 :(得分:0)
您是否尝试过这两个而不是指定dpi的
android:layout_height="fill_parent"
android:layout_width="fill_parent"
答案 2 :(得分:0)
您是否使用过 LazyAdapter 。
试试这个......
<强> Demo.java:强>
public class Demo extends Activity {
LazyAdapter adapter;
ListView lv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.demo_layout);
lv = (ListView) findViewById(R.id.list);
ArrayList<String> songsList = new ArrayList<String>();
songsList.add("Song 1");
songsList.add("Song 2");
songsList.add("Song 3");
adapter=new LazyAdapter(this, songsList);
lv.setAdapter(adapter);
}
public void onListItemClick(ListView l, View v, int position, long id) {
//Do Something here
}
}
<强> demo_layout.xml:强>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#b5b5b5"
android:textSize="20sp"
android:dividerHeight="1dp"/>
</RelativeLayout>
<强> LazyAdapter.java:强>
public class LazyAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<String> data;
private static LayoutInflater inflater=null;
public LazyAdapter(Activity a, ArrayList<String> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.lazyadapter_layout, null);
TextView title = (TextView)vi.findViewById(R.id.title); // title
String song;
song = data.get(position);
// Setting all values in listview
title.setText(song);
return vi;
}
}
<强> lazyadapter_layout.xml:强>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="480dp"
android:background="#404040"
android:gravity="center"
android:text="ViewSwitcher"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</LinearLayout>
希望这可以帮助你!!!
有关详细信息refer this tutorial.