BUTTON LAYOUT

Giorgio Sfiligoi 391 Reputation points
2022-12-26T16:07:43.967+00:00

In my Xamarin.Android project I have a row of buttons such as:

    <LinearLayout  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:id="@+id/keyb_row2"  
        android:orientation="horizontal"  
        >  
        <Button  
            android:text="UD"  
            style="@style/text3Button"  
            />  
        <Button  
            android:text="Z"  
            style="@style/textButton"  
            />  
        <Button  
            android:text="X"  
            style="@style/textButton"  
            />  
        <Button  
            android:text="C"  
            style="@style/textButton"  
            />  
           ....  
    </LinearLayout>  

With styles defined as:

   <style name="textButtonBase">  
       <item name="android:layout_height">44dp</item>  
       <item name="android:layout_marginLeft">1dp</item>  
       <item name="android:layout_marginRight">1dp</item>  
       <item name="android:layout_marginTop">2dp</item>  
       <item name="android:layout_marginBottom">2dp</item>  
       <item name="android:textAllCaps">false</item>  
       <item name="android:background">@drawable/rounded_corners</item>  
     </style>  
     <style name="textButton" parent="textButtonBase">  
       <item name="android:layout_width">34dp</item>  
       <item name="android:textSize">20sp</item>  
     </style>  
     <style name="text3Button" parent="textButtonBase">  
       <item name="android:layout_width">52dp</item>  
       <item name="android:textSize">16sp</item>  
     </style>  

It happens that for all the buttons I get the error message: "Missing attribute: layout_height" (where in fact height is defined in style textButtonBase); however, the program compiles and runs successfully.

However, the most important issue is that the button 'UD' displays dropped down:

274049-screenshot.png

I can align the button by overriding marginTop=0: granted that this trick works, I would like to understand the reason for this strange behavior.

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2022-12-27T03:41:25.603+00:00

    Hello,

    I get the error message: "Missing attribute: layout_height"

    VS cannot detect attributes in styles

    the most important issue is that the button 'UD' displays dropped down:

    Based on my test, android:textSize caused this issue, if you set the same textsize and use dp for textsize, the button 'UD' will not displays dropped down:

       <style name="textButton" parent="textButtonBase">  
               <item name="android:layout_width">34dp</item>  
               <item name="android:textSize">20dp</item>  
           </style>  
             
           <style name="text3Button" parent="textButtonBase">  
               <item name="android:layout_width">54dp</item>  
               <item name="android:textSize">20dp</item>  
           </style>  
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.