[英]Gridview row height in android
我有一個gridview,它加載了textview,並且正在為文本視圖設置背景圖像。 我想根據某些邏輯來改變textviews的高度,但要保持gridview行的高度不變。 我嘗試了此代碼,但id無效。 電視是我的textview
int Height = 150 + Integer.parseInt(PostCount);
if(Height >= MaxHeight)
{
Height = MaxHeight;
}
tv.setLayoutParams(new GridView.LayoutParams(200, Height));
如果我使用以上內容,則行會重疊。 我也嘗試了此操作而不設置gridview參數。
int Height = 150 + Integer.parseInt(PostCount);
if(Height >= MaxHeight)
{
Height = MaxHeight;
}
tv.setHeight(Height);
tv.setWidth(200);
這樣只會創建寬度和高度均勻的網格視圖。 我想要恆定的寬度,但是應該能夠根據邏輯設置高度。 不知道我要去哪里錯我不確定應該去表格布局還是網格布局。 幫助將不勝感激。
提前致謝。
不知道這是否有幫助,但也許可以將LinearLayout用作每行的父級,將textview用作子級。
在grid_item.xml中
<LinearLayout
android:layout_width="xdp" <!-- where x is the max width for each row -->
android:layout_height="ydp" <!-- where y is the max height for each row -->
<TextView
// rest of the definition for Textview
</TextView>
</LinearLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.