How to programmatically set style attribute in a view

前端 未结 11 2137
北恋
北恋 2020-11-22 06:38

I\'m getting a view from the XML with the code below:

Button view = (Button) LayoutInflater.from(this).inflate(R.layout.section_button, null);
11条回答
  •  滥情空心
    2020-11-22 07:00

    I faced the same problem recently. here is how i solved it.

    
    
    
        
        
    
        
    
        
        
        
    
       
    
    
    • I used a LinearLayout with android:weightSum="2"
    • I gave to the two child elements android:layout_weight="1" (I gave each 50% of the parent space(width & height))
    • And finally, i gave the two child element different background colors to have the final effect.

    Thanks !

提交回复
热议问题