Question

I have a layout with 4 buttons (which I am trying to get of equal size). The problem is I don't want the text on my first button to be ellipsized. I have tried many things: setting the ellipsize attribute to "none", setting the singleLine attribute to false, cutting off the paddings, none of them worked.

Everything looks fine in eclipse graphical layout, but when I try it on a real device, the said issue occurs, no matter how large the screen is. At first, I thought it was because the paddings ( I define a custom background for the button in an .xml and I use paddings on that shape). However, removing them did not work.

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:gravity="center"
    android:background="@drawable/gradient_bkg"
    tools:context=".StartActivity" >

    <TableLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

    <TableRow android:layout_weight="1.0">
   <LinearLayout 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_marginBottom="15dp"
       android:gravity="center">

        <Button
            android:id="@+id/random_words"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginRight="15dp"
            android:layout_weight="1.0"
            android:background="@drawable/button_sexy"
            android:text="Random two words"
            android:drawableLeft="@drawable/drinks"/>

        <Button
            android:id="@+id/no_data"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="15dp"
            android:layout_weight="1.0"
            android:background="@drawable/button_sexy"
            android:text="No data"
            android:drawableLeft="@drawable/body_data" />

   </LinearLayout></TableRow>

    <TableRow android:layout_weight="1">
   <LinearLayout
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_marginTop="15dp"
       android:gravity="center" >

       <Button
           android:id="@+id/result"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:layout_marginRight="15dp"
           android:layout_weight="1"
           android:background="@drawable/button_sexy"
           android:text="Result"
           android:drawableLeft="@drawable/results" />

       <Button
           android:id="@+id/reset"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:layout_marginLeft="15dp"
           android:layout_weight="1"
           android:background="@drawable/button_sexy"
           android:text="Reset"
           android:drawableLeft="@drawable/reset"/>
   </LinearLayout>
   </TableRow>
   </TableLayout>

</RelativeLayout>
Was it helpful?

Solution

Your code is amazing and perfect. The problem you indicated will occur only for lower APIs, because you added a Theme.Holo in your manifest, which acts strange for older APIs.

Simplest solution, since you are using a custom LAF anyway, : replace Theme.Holo with Theme.Black in your manifest.

OTHER TIPS

I think the problem is related to the usage of wrap_content on so many levels of your layout. I have seen that this causes the individual items trying to be smart sometimes and are auto adjusting incorrectly or at leas in an unexpected way. Try to put your buttons on top level layout to test if you can get the correct behaviour when using match_parent instead.

But in the end, playing around with combinations of wrap_content and match_parent can consume quite lot of time. A fast way forward may be to set the buttons to fixed size, but then please make sure you set them somewhat bigger than you think is enough to make sure it will work on many different screen sizes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top