0
我一直在爭取了兩天,嘗試在Android中創建自定義佈局,分爲3部分,一個「投票」計數器容器,顯示投票人數消息,一個文本消息容器,其中將包含文本和消息的作者以及將用於對消息進行投票的按鈕容器。Android:容器XML佈局包裝重量和填充高度
到目前爲止,我有這樣的代碼
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/containerInner"
>
<!-- # VOTES CONTAINER -->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/containerVotes"
android:layout_centerVertical="true"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/votesPost"
android:textStyle="bold"
android:textSize="16sp"
/>
</RelativeLayout>
<!-- MESSAGE CONTAINER -->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/containerText"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:layout_toRightOf="@+id/containerVotes"
android:background="@color/gray"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:id="@+id/titleGlobus"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/AutorGlobus"
android:textColor="#000000"
android:textSize="12sp"
android:textStyle="italic"
android:maxWidth="180dp"
android:layout_weight="0.1"
android:layout_below="@+id/titleGlobus"
/>
</RelativeLayout>
<!-- VOTE UP/DOWN CONTAINER -->
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/containerButtons"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/containerText"
android:layout_toEndOf="@+id/containerText"
>
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/containerButtonUp"
>
<at.markushi.ui.CircleButton
android:layout_width="32dip"
android:layout_height="32dip"
android:src="@mipmap/ic_arrow_drop_up_black_24dp"
app:cb_color="@color/white"
app:cb_pressedRingWidth="8dip"
android:id="@+id/upvote_button"
/>
</RelativeLayout>
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/containerButtonDown"
android:layout_below="@+id/containerButtonUp"
>
<at.markushi.ui.CircleButton
android:layout_width="32dip"
android:layout_height="32dip"
app:cb_color="@color/white"
app:cb_pressedRingWidth="8dip"
android:src="@mipmap/ic_arrow_drop_down_black_24dp"
android:id="@+id/downvote_button"
/>
</RelativeLayout>
</RelativeLayout>
我使用上面的代碼在手機越來越佈局是這樣的:
我想實現這個:
因此,有我需要在這裏實現兩兩件事:
充分利用RelativeLayout的containerText填補其上位容器的整個高度。
將容器右側的作者名稱對齊,但僅在「消息」TextView的末尾對齊。
我一直在試圖解決問題,修復改變containerText容器的高度FILL_PARENT沒有成功,改變一路攀升到主容器中的所有height屬性FILL_PARENT。
如果我嘗試使用alignParentRight = true將作者姓名對齊到右側,那麼RelativeLayout將佔據整個屏幕空間,並推出按鈕容器。我也嘗試改變我將不同佈局尊重他人的方式,改變toLeftOf或toRightTo,並帶來可怕的結果。
任何幫助將不勝感激,因爲我堅持這個問題。
乾杯!
插入 '機器人:layout_alignParentRight = 「真」' 使得TextView的以填充整個寬度 - >給這個輸出:http://imgur.com/a/a5EkB 刪除layout_below使其顯示在消息的右側,就好像佈局不能垂直增長一樣。 – PayToPwn
您是否添加了alignParentBottom?它應該堅持到容器的底部 –
是的,我改變了layout_height中的match_parent並添加了alignParentBottom和alignParentRight,但是我得到了我在最後一條評論中發佈的圖像。 – PayToPwn