試圖讓高分名單,這是滾動的,看起來像這樣:GridView的不同列大小
foo 1000
bar 876
foobar 500
foobarfoo 1
我目前正在與一個GridView這樣做。我想將名稱列的寬度設置爲屏幕的60%,並將分數列的寬度設置爲40%。可能嗎?
目前我正在嘗試通過一個costum適配器。這裏是它的getview功能:
public View getView(int position, View convertView, ViewGroup parent) {
TextView tv;
if (convertView == null) {
tv = new TextView(context);
tv.setTextSize(25);
tv.setTextColor(Color.WHITE);
if (position % 2 == 0)
{
tv.setLayoutParams(new GridView.LayoutParams((width/10)*6, 50));
}
else
{
tv.setLayoutParams(new GridView.LayoutParams((width/10)*4, 50));
}
}
else {
tv = (TextView) convertView;
}
tv.setText(texts[position]);
return tv;
}
該佈局是由gridview和一個按鈕在底部構建。該XML文件是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/top">
<GridView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/grid"
android:numColumns="2"
android:columnWidth="0dp"
>
</GridView>
<Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/backbutton" android:text="@string/backstr"></Button>
</LinearLayout>
所以問題再次:是否有可能設置GridView允許添加不同大小的列?如果是的話,那我的方法很好? (可能不會,因爲它不工作:))我只是錯過了什麼?
預先感謝您!
你能嘗試設置列寬爲wrap_content代替0dp,然後看看是否可行? –
這可惜不是列寬的有效值。但感謝評論! – Szellszi
在這種情況下,您可以使用ListView而不是GridView,並且對於每一行,使用包含兩個文本視圖(LinearLayout優先)的佈局,並將其填充到適配器的getView方法中。 –