0

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>
lazexe
  • 367
  • 4
  • 19

3 Answers3

0

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"/>
henry4343
  • 3,871
  • 5
  • 22
  • 30
0

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" />

androCoder-BD
  • 498
  • 7
  • 13
  • It's completely wrong!! In Buttons you should have **layout_weight="50"**, not weightSum. And you can use lower values. And you must set the button widths to **0dp**. – Phantômaxx Dec 26 '13 at 15:30
  • weightSum didn't help! – lazexe Dec 26 '13 at 15:30
  • extremely sorry. My Bad! that should be "layout_weight=50" within – androCoder-BD Dec 26 '13 at 15:56
  • well! you should set your view width to fill parent if you are using weightSum. Because, it will only have half of the space left for it. So, when you are using it fill parent it will take only that half part. Just give it a try. It will work definitely (Insha-Allah). :) – androCoder-BD Dec 26 '13 at 16:05
0

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>