方法二:" />
当前位置: 代码迷 >> Android >> 方法二:
  详细解决方案

方法二:

热度:69   发布时间:2016-04-28 06:02:01.0
android应用开发 按钮显示两行文本

自己写了个电话拨号器的程序给男朋友玩,用来专门打我的手机号,为了把界面做的好看一点,需要用到显示两行文本的按钮,在网上搜罗了两种方法,记录在下面,跟大家一起分享一下,希望能帮到需要的人。

方法一:

<LinearLayout 

      android:id="@+id/container" 

      android:layout_width="wrap_content" 

      android:layout_height="wrap_content" 

      tools:context="com.example.test.MainActivity"

      tools:ignore="MergeRootFrame" 

      android:clickable="true" 

      android:focusable="true" 

      android:orientation="vertical" 

      android:background="@android:drawable/btn_default">

      <TextView 

              android:text="Hello" 

              android:layout_width="wrap_content" 

              android:gravity="center_horizontal"

              android:layout_height="wrap_content" 

              android:layout_weight="1"/>

     <TextView 

              android:text="android" 

              android:layout_width="wrap_content" 

              android:layout_height="wrap_content" 

              android:layout_gravity="center_horizontal" 

              android:layout_weight="1"/>

</LinearLayout>

效果如下图:


由于本人是初学者,用这种方法的时候没想到绑定监听器的办法,希望路过的大神指点一二。

方法二:

<Buttton

        android:id="@+id/button1"

        android:layout_width="wrap_content" 

        android:layout_height="wrap_content" 

        android:textColor="#FF0000"

        android:textSize="20sp"

        android:text="呼叫丫头 &#10; (联通号)"/>

这种方法是用“&#10;”这个符号实现一个按钮显示两行文本,这样就可以为这个按钮绑定监听器

但是在用的时候,[email protected]/...”,就会报错

瑾此一记,希望对你有用



  相关解决方案