Android Button layout with big text size

会有一股神秘感。 提交于 2019-12-13 03:58:16

问题


I'm trying to make two identical buttons with the same height, but when the text is too long (the second button) then breaks markup. How can I fix it?

xml layout:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent">

        <Button

            android:text="test"
            android:layout_height="100dp"
            android:layout_width="0dp"
            android:layout_weight="1"/>

        <Button
            android:padding="0dp"
            android:text="Arterial tension disturbance"
            android:layout_height="100dp"
            android:layout_width="0dp"
            android:layout_weight="1"/>

        </LinearLayout>

</LinearLayout>

回答1:


Add android:singleLine="true"

<LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

    <Button
        android:singleLine="true"

        android:text="test"
        android:layout_height="100dp"
        android:layout_width="0dp"
        android:layout_weight="1"/>

    <Button
        android:singleLine="true"
        android:padding="0dp"
        android:text="Arterial tension disturbance"
        android:layout_height="100dp"
        android:layout_width="0dp"
        android:layout_weight="1"/>

    </LinearLayout>




回答2:


use wrap_content instead of 0dp

    <Button
        android:padding="0dp"
        android:text="Arterial tension disturbance"
        android:layout_height="100dp"
        android:layout_width="wrap_content"
        android:layout_weight="1"/>



回答3:


You can try this: (Edited)

<LinearLayout
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:orientation="vertical"
       android:weightSum="100" >


       <Button
          android:layout_width="fill_parent"
          android:text="yourText"
          android:layout_height="wrap_content"
          android:layout_weight="50" />

      <Button
          android:layout_width="fill_parent"
          android:text="yourText"
          android:layout_height="wrap_content"
          android:layout_weight="50" />



来源:https://stackoverflow.com/questions/20786948/android-button-layout-with-big-text-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!