Making a LinearLayout act like an Button

前端 未结 10 2084
无人及你
无人及你 2020-11-29 19:09

I have a LinearLayout that I\'ve styled to look like a button, and it contains a few text/ImageView elements. I would like to make the whole

10条回答
  •  死守一世寂寞
    2020-11-29 19:23

    First you'll want a selector to define the different states. For example, in an XML file:

    
        
        
        
    
    

    I haven't tried it, but you can possibly set the LinearLayout's android:background to this selector, and set android:clickable to true and it'll work.

    If it doesn't, you could switch to using a RelativeLayout, and make the first element a button with this selector as the background and fill_parent for its layout width and height. In this case, just use a regular Button and set android:background to your selector. You don't have to put text on your button.

提交回复
热议问题