[英]RelativeLayout with MATCH_PARENT doesn't work
這就是我想要實現的目標:我在桌面上有很多表行。 每行應該有兩個文本視圖,產品標題和副標題相互疊加(副標題尚未實現)。 應該左對齊。 在右邊,我想要一個微調器來選擇數量。
文本來自數據庫,當然有不同的長度。
這是我到目前為止所提出的:
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/barmenu"
android:background="#99ffff"
android:scrollbars="vertical">
<TableRow
android:layout_height="wrap_content"
android:background="#ffff99"
android:layout_width="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:background="#0000ff">
<TextView
android:id="@+id/productTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#88ffff"
android:ellipsize="end"
android:padding="2dp"
android:singleLine="true"
android:text="Product name"
android:textColor="#000000"
android:gravity="left"
android:textSize="13sp"
android:textStyle="bold" />
<Spinner
android:gravity="right"
android:layout_height="40dp"
android:layout_toRightOf="@id/productTitle"
android:width="100dp"
android:layout_width="wrap_content" />
</RelativeLayout>
</TableRow>
<TableRow
android:layout_height="wrap_content"
android:background="#ffff99"
android:layout_width="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:background="#0000ff">
<TextView
android:id="@+id/productTitle2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#88ffff"
android:ellipsize="end"
android:padding="2dp"
android:singleLine="true"
android:text="Some long long long long name"
android:textColor="#000000"
android:gravity="left"
android:textSize="13sp"
android:textStyle="bold" />
<Spinner
android:gravity="right"
android:layout_height="40dp"
android:layout_toRightOf="@id/productTitle2"
android:width="100dp"
android:layout_width="wrap_content" />
</RelativeLayout>
</TableRow>
</TableLayout>
</ScrollView>
Screendump:
第一個問題是RelativeLayout沒有填寫表格行的寬度。 第二個問題:紡紗廠沒有正確對齊。
我錯過了什么?
最好的問候艾倫
機器人:fillViewport = “真”
將此行添加到您的ScollView屬性中,您就完成了:)
我會讓它更簡單,更輕松。 只需對所有這4個視圖使用RelativeLayout
。 將兩個微調器對齊並使用 - match_parent
進行textview,並將相對微調器添加到toLeftOf
。 我想你會看到你想要的東西。
將android:layout_weight="1"
到你的relativelayout
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.