我有一個列表視圖,並填充一個自定義適配器。我希望我所有的listview項目都有25%的高度。我試圖使用沒有結果的佈局權重。任何幫助?25%高度的列表視圖項目
這裏是我的代碼
NavigationAdapter
public class NavigationAdapter extends ArrayAdapter<String> {
private final Activity context;
private final String[] NavigationTexts;
private final String[] NavigationImages;
public NavigationAdapter(Activity context, String[] NavigationTexts, String[] NavigationImages) {
super(context, R.layout.navigation_layout, NavigationTexts);
this.context=context;
this.NavigationTexts=NavigationTexts;
this.NavigationImages=NavigationImages;
}
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater=context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.navigation_layout, parent, false);
TextView Name = (TextView) rowView.findViewById(R.id.NavigationText);
ImageView ImgButton = (ImageView) rowView.findViewById(R.id.NavigationImage);
Name.setText(NavigationTexts[position]);
int resID = context.getResources().getIdentifier(NavigationImages[position], "drawable", getContext().getPackageName());
ImgButton.setImageResource(resID);
return rowView;
}
}
和我的佈局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="150dp"
android:id="@+id/NavigationImage"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:scaleType="fitXY" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/NavigationText"
android:layout_alignBottom="@+id/NavigationImage"
android:layout_marginBottom="56dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#ffffff"
android:gravity="center" />
</RelativeLayout>
是的,很好。告訴我,你想有4個listview項目,每個項目佔25%的空間?或者你想要別的東西佔25%的空間? – Vucko