[英]Size LinearLayout to the Width of ImageView
在我的Fragment XML中,我有一個imageview作為背景。 在相同的布局中,我得到了LinearLayout,其中包含一些按鈕,這些按鈕應在視圖上水平查看,並且寬度與背景相同。 由於wrap_content,我的代碼將其大小調整為屏幕的寬度。 如何調整它的大小到imageview?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="45sp" >
<ImageView
android:src="@drawable/background_detail_view"
android:id="@+id/detailview_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/detailview_background_description" />
<!-- more widgets -->
<LinearLayout
android:id="@+id/detail_button_container"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_above="@+id/titel" >
<Button
android:id="@+id/detail1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1"/>
<Button
android:id="@+id/detail2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2"/>
<Button
android:id="@+id/detail3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3"/>
<!-- more buttons -->
</LinearLayout>
我嘗試以編程方式獲取寬度並將其分配給新的layoutparams,但由於視圖尚未渲染,因此返回0。
在您的LinearLayout中,設置android:background="@drawable/background_detail_view"
參數,以便您的LinearLayout具有此背景,而不是使用ImageView。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.