How To Display Border To Imageview?

后端 未结 3 694
一个人的身影
一个人的身影 2020-11-28 05:23

Friends How To Display Border To Imageview ?

I Want To Result Like Mobile gallery all image display with border.

plz give me ans thanks for advance....

3条回答
  •  执念已碎
    2020-11-28 05:51

    You can create a resource (layer drawable xml) for your ImageView's "border" (actually background), and declare in your theme that the ImageView's background resource is the drawable xml.

    If you need this "border" to be changed based on the ImageView's state (focused, selected, etc.), then you should create more layer drawables, and put them together into a selector xml (state drawable).
    Then in your theme you should set the ImageView's background to be this selector.xml.

    Update
    Below is a sample of how to specify a simple border to your images, that will result in

    efteling with border

    You have to

    1. create a new layer drawable file (image_border.xml),
    2. modify/create your styles.xml file
    3. modify/create your colors.xml file
    4. modify your layout xml file (or your code) to apply the style to the ImageView.

    res/drawable/image_border.xml

    
    
        
            
                
            
        
        
            
                
            
        
    
    

    res/values/styles.xml
    Add the following lines:

    
    

    res/values/colors.xml
    Add the following lines:

    #40990000
    #FF660000
    #FFFF3333
    

    And finally specify the style of your ImageView in your layout xml:

    
    

提交回复
热议问题