我有两个问题:
在布局xml中,有一个ImageButton
drawable是资源。对于此imageButton,drawable-ldpi至xxhdpi具有不同的大小,其宽度取决于应用程序正在运行的设备。在布局xml的底部,我有一个9-patch按钮,我希望它具有与drawable / imageButton相同的宽度。
如何从1继承动态,到另一个布局xml中的第二个9-patch按钮?
我的尝试是使用RelativeLayout
with wrap_content
,它可以很好地包装所有内容。当我设置buttonStart
宽度时,match_parent
它将使用整个屏幕,而不是UIWrapper的宽度。任何帮助表示赞赏。谢谢!
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_activity_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:focusable="true"
android:screenOrientation="portrait"
tools:context=".MainActivity" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/UIWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="62dp" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imageWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" >
<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="?android:attr/selectableItemBackground"
android:src="@drawable/my_gfx" />
<TextView
android:id="@+id/textViewTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center_horizontal|top"
android:clickable="false"
android:shadowColor="@color/LightYellow"
android:shadowDx="0.0"
android:shadowDy="0.0"
android:shadowRadius="24"
android:text="Some Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/DarkBlue"
android:textSize="48dp" />
</RelativeLayout>
<TextView
android:id="@+id/T0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imageWrapper"
android:layout_below="@+id/imageWrapper"
android:layout_marginTop="10dp"
android:text="@string/label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/FloralWhite" />
<RadioGroup
android:id="@+id/T1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/T0"
android:layout_below="@+id/T0" >
<RadioButton
android:id="@+id/radioButton0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:enabled="true"
android:singleLine="true"
android:text="@string/rd_0"
android:textColor="@color/White" />
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="true"
android:text="@string/rd1"
android:textColor="@color/FloralWhite" />
</RadioGroup>
<Button
android:id="@+id/buttonStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="14dp"
android:background="@drawable/default_button"
android:text="@string/btn_start"
android:textColor="@color/FloralWhite" />
</RelativeLayout>
</RelativeLayout>
第一的
要获得相同的宽度,请使用:
android:id="@+id/buttonStart"
android:layout_alignRight="@+id/..."
android:layout_alignLeft="@+id/..."
并设置要用于调整按钮宽度的视图的ID。但是您只需要使用一个RelativeLayout即可获得结果。您可以张贴想要得到的图片吗?
xmlns:android="http://schemas.android.com/apk/res/android"
在第一个元素上重复一次属性。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句