通过嵌套视图在android中显示按钮
我有按钮的xml代码 它只有一个文本通过嵌套视图在android中显示按钮,android,Android,我有按钮的xml代码 它只有一个文本 <Button android:id="@+id/BuyButton" android:layout_width="81sp" android:layout_height="wrap_content" android:text="buy" /> 但如何将上述按钮设置为:: 显然,按钮
<Button
android:id="@+id/BuyButton"
android:layout_width="81sp"
android:layout_height="wrap_content"
android:text="buy" />
但如何将上述按钮设置为::
显然,按钮中有两个文本。。。。如何在一个按钮中嵌套两个文本尝试:
android:text="Buy \n Price"
请尝试以下代码:
<Button
android:id="@+id/BuyButton"
android:layout_width="81sp"
android:layout_height="wrap_content"
android:text="buy \n Price" />
您还可以使用:
<RelativeLayout
android:id="@+id/buttonLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@drawable/icon">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Buy" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="15dp"
android:text="Price" />
</RelativeLayout>
试试这个。。
两行之后价格就来了
<Button
android:id="@+id/BuyButton"
android:layout_width="81sp"
android:layout_height="wrap_content"
android:text="buy \n \n price" />
如果我想在一个按钮中包含两个独立的文本视图,该怎么办。。。。为什么我要问的是,将来我会从数据库中输入购买价值,所以。。。。任何ideas@Sky如果您想使其成为动态的,那么您可以在运行时生成一个字符串,并可以使用setText()
方法在按钮中显示相同的字符串。是的。。。。。。但是,请从一个叫Exception的人对这个问题的回答中找出答案。。。如果我想在一个按钮内有两个独立的文本视图,可以用什么来代替按钮。。。。为什么我要问的是,将来我会从数据库中输入购买价值,所以。。。。在呈现期间引发的异常:android.widget.button不能转换为android.view.ViewGroup,如果您在按钮k内引用textview,则会出现任何引用按钮内文本视图的想法。那么如何从数据库中显示按钮内文本?如果您使用单按钮而不是两个textview,则:,在类文件中:按钮1.setText(DataFromDB+“\n价格”)代码>您的答案是信息丰富的,但整个内容(包括两个视图)应该是按钮。。。任何想法都可以请你详细说明你在eclipse中粘贴这段代码并观察差异,它将像按钮一样查看,而不是像视图一样查看,请查看!!!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
style="@android:style/ButtonBar"
android:layout_width="81dp"
android:layout_height="81dp"
android:orientation="vertical" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:text="buy" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:text="Price" />
</LinearLayout>
</LinearLayout>