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="呼叫丫頭 (聯通號)"/>
這樣的方法是用“ ”這個符號實現一個button顯示兩行文本,這樣就能夠為這個button綁定監聽器
可是在用的時候,[email protected]/...”,就會報錯
瑾此一記。希望對你實用
android應用開發 button顯示兩行文本