Ich habe eine Listview und ich bevölkere es mit einem benutzerdefinierten Adapter. Ich möchte, dass alle meine Listenansicht-Elemente eine Höhe von 25% haben. Ich habe versucht, Layout-Gewichte ohne Ergebnis zu verwenden. Irgendeine Hilfe?Listview Elemente mit 25% Höhe
hier ist mein Code
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;
}
}
und mein Layout-Datei
<?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>
Ja, gut. Sag mir, du möchtest 4 Listview Items haben, die jeweils 25% des Platzes einnehmen? Oder willst du etwas anderes, um 25% Platz zu haben? – Vucko