按键采用自定义XML布局 [英] Button with custom XML layout
本文介绍了按键采用自定义XML布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能创建一个自定义XML布局的按钮?
Is it possible to create a button with a custom xml layout?
我有这样的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="1dp"
android:background="#7e7e7e">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:background="#f9f9f9">
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="ButtText"
android:textColor="#000000">
</TextView>
<ImageView
android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/arrow"
android:layout_alignParentRight="true">
</ImageView>
</RelativeLayout>
</LinearLayout>
现在我想用这个按钮上。任何人都知道我该怎么做呢?结果
我在想,如果我有这样的扩展按钮Button.java文件。然后的setView(R.layout.mylayout.xml); ...但是,这是为了方便,它显然不工作
Now I want to use this on a button. Anyone know how I can do this?
I was thinking if I had Button.java file that extended Button. And then setView(R.layout.mylayout.xml); ... but that was to easy, and it clearly not working
问候马丁
推荐答案
您不能随便使用该布局在<$ C $ C>按钮面对。您可以使用机器人实现类似的外观:drawableRight
在按钮
属性,虽然
You cannot literally use that layout on the face of a Button
. You can achieve a similar look using the android:drawableRight
property on a Button
, though.
这篇关于按键采用自定义XML布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文