6

hi i have to realize this layout . it has this layout. inactive buttons

I could try to use the icons as imagebuttons but the active state of a button is somewhat like this one !

one button has been pressed

How should i proceed with this ?

3
  • 1
    That's too much of a question to give you one answer. The buttons on top are quite easy positioned ImageButtons. Tricky is the circle in the middle. You can create ImageButtons for each part and position them programmatically around the circle, but the clickable areas will overlap. So I think the best way is to make the whole circle with all buttons clickable and have a touch listener that detects whicht part of the circle was actually clicked. Maybe you can simplify and focus your question around that specific part. BTW: Nice design! Commented Oct 20, 2013 at 9:14
  • @jboi you got it 100%. will I be bale to show both states of each button using the touch listner method? Any eaxample ? Commented Oct 20, 2013 at 13:46
  • 1
    For the different states of drawables you can use selector or LevelListDrawable. With them you define the different bitmaps for touched and untouched state at different levels. With ImageView.setLevel(...) you set the level at runtime. Commented Oct 20, 2013 at 15:37

1 Answer 1

1

You should use selector as follows:

  1. Prepare 2 images for button states, and put it into res/drawable folder.

    button_normal_green.png – Default image button.

    button_pressed_yellow.png – Display when button is pressed.

  2. Now, create a new XML file in “res/drawable/” folder, in whatever name you want, in this case, we just give a name as “new_button.xml“. This file defined which button state is belong to which image.

    <?xml version="1.0" encoding="utf-8"?>
      <selector xmlns:android="http://schemas.android.com/apk/res/android">
         <item android:drawable="@drawable/button_pressed_yellow" android:state_pressed="true" />
    
         <item android:drawable="@drawable/button_normal_green" />
      </selector>
    

3.set background to button

<ImageButton
    android:id="@+id/imageButtonSelector"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/new_button" />

Have a look at Complete Example

Sign up to request clarification or add additional context in comments.

2 Comments

thanks, my actual problem is the shape of buttons , if i use rectangular shapes either i have to either leave some part of the buttons to be unclickable or they will overlap
How can selector help buttons to be non-rectangular?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.