我有一個簡單的XML我試圖膨脹,並與佈局掙扎。我想要實現的是非常簡單的(或者我認爲),所以我確信我錯誤地做了這件事。基本上我有三個元素,2個TextViews和一個Imageview。我希望兩個文本框放在一起,右邊的圖像對齊右側,其視圖將它與圖像的大小相匹配。就像這樣:將佈局設置爲其內容的大小
Text 1 |==|
Text 2 would be below text 1 |==|
我的繼承人XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/entry_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="horizontal"
android:paddingRight="?android:attr/scrollbarSize" >
<LinearLayout
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/entry1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:gravity="left"
android:paddingLeft="@dimen/tab_host_default_height"
android:text="@string/test_string"
android:textStyle="bold" />
<TextView
android:id="@+id/entry2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:text="@string/test_string" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
>
<ImageButton
android:id="@+id/entry3"
style="@style/ImageButtonBDTheme"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/activated_background_holo_light"
android:contentDescription="@string/click_for_repair_report"
android:paddingRight="5dp"
android:src="@drawable/entry_link" />
</LinearLayout>
</LinearLayout>
問題是,我不能要顯示的圖像沒有硬編碼包含兩個文本框的LinearLayout的大小。
任何幫助表示讚賞!
你明白了!感謝您的快速回復:) – xceph
你可能可以解釋這是如何工作的?我會認爲在一箇中設置權重,但不是另一個只會顯示該元素。 – xceph
什麼尺寸是需要顯示imagebutton它將採取和其餘的大小是由textview佈局使用.. –