How to align Radio button at the center of the screen

前端 未结 11 1391
误落风尘
误落风尘 2021-01-04 02:13

I am using Radio buttons as tab in my application.

I have loaded images for it, but they are aligning towards left side. how to make them align at center.

11条回答
  •  星月不相逢
    2021-01-04 03:03

    I had similar issue before, I figure it out, so I try to explain it for you.

    runtime screenshot

    above is my app screenshot, as you can see, I also did the same, I had a menu align screen bottom, they're a RadioGroup and three RadionButton inside it, I want each menu icon align center for RadionButton, the shadow image(9-patch) shown together when Button check event trigger.
    At first, I used android:button attribute refers to a drawable selector, the selector has two drawable state between check and uncheck, but I cannot align the menu icon center and make the shadow image fill up by RadionButton, they looks like it :

    enter image description here

    I tried included android:layout_gravity=center and android:gravity=center with the RadionButton, but it also didn't got effect. after that, my workmate told me the android:button attribute is refers to foreground rather than background, then I use android:background instead of android:button and it worked, below is my code :

    
    
        
    
        
    
        
    
    
    

    the menu_item_selector is important thing because it had gravity setting :

    
        
        
        
            
        
    
    

    cause I had two images to draw when user turn Button state is checked, the shadow background image and icon active state image, so I used layer-list to implement it, the active icon also had gravity setting, below is menu_item_layer_list code :

    
        
        
            
        
    
    

    I don't know that solution was perfect or not, because I always implement it as a view and draw myself. But I think Android SDK supplied more convenient component let's finish work with xml configuration, we should be learn and use it.

提交回复
热议问题