如何设置图像RelativeLayout背景
问题描述:
我有一个RelativeLayout
与2 Button
s里面。如何设置图像RelativeLayout背景
一个Button
有layout_alignParentLeft="true"
财产和其他按钮有layout_alignParentRight="true"
我想设置我的RelativeLayout的背景,显示在中间的图像。我有一个play.9.png
在我的绘制和使用下面的代码:
<RelativeLayout
android:id="@+id/relativeLayout12"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:background="@drawable/play" // background line
>
<Button
android:id="@+id/bAbout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="but1" />
<Button
android:id="@+id/bSync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="but2" />
</RelativeLayout>
但是当我使用的背景线,我Button
小号想念自己的位置
见下
的形象,但我希望我的RelativeLayout
是这样的:
什么是错的?
答
最后我做到这一点的家伙 我用这个代码:
<RelativeLayout
android:id="@+id/relativeLayout12"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:background="@drawable/play" // background line
>
<Button
android:id="@+id/bAbout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="but1" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/play" />
<Button
android:id="@+id/bSync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="but2" />
</RelativeLayout>
,我的结果是这样的:
和工作原理。谢谢大家
答
<RelativeLayout
android:id="@+id/relativeLayout12"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:background="@drawable/play" // background line
>
<Button
android:id="@+id/bAbout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="but1" />
<Button
android:id="@+id/bSync"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="but2" />
</RelativeLayout>
答
我想你应该从两个按钮删除
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
,并设置按钮高度 'FILL_PARENT'。
+0
我这样做,但这也不工作 – aTa 2012-07-31 11:05:05
答
试试这个。
RelativeLayout rLayout = (RelativeLayout) findViewById (R.id.rLayout);
Resources res = getResources();
Drawable drawable = res.getDrawable(R.drawable.newImage);added to the res folder
rLayout.setBackground(drawable);
请问您可以上传'play.9.png'图片吗?即使你的代码对我来说工作正常 – sunil 2012-07-31 11:20:20