zoukankan      html  css  js  c++  java
  • android应用开发 button显示两行文本

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

    方法一:

    <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;”这个符号实现一个button显示两行文本,这样就能够为这个button绑定监听器

    可是在用的时候,假设符号两端都是用的“@string/...”,就会报错

    瑾此一记。希望对你实用



  • 相关阅读:
    Android 剪贴板操作方法在不同版本API下的使用
    Android android:persistentDrawingCache的几个默认属性值介绍
    android 4.0 external下功能库说明
    Android gc overhead limit exceeded
    android onTerminate()方法调用需要注意的点
    android onTrimMemory()和onLowMemory()
    思维游戏(3)之时间问题
    思维游戏(2)之几根蜡烛
    思维游戏之分辨姐妹(1)
    如何根据用例图写出用例描述
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/7258410.html
Copyright © 2011-2022 走看看