views:

115

answers:

1

I have a gallery with the TextView to achieve the segment controller on the image below. I can achieve it by the ApiDemo's Gallery Example but I am lagging on the look and feel of the gallery.

I want to do the backgrounds, Selected/deselected and selected item won't be cone to the center of the screen.

Any Idea or Articles are most Thankful.

image

I have tried to get using 2 ways. that are:

  1. Gallery View
  2. horizontal ScrollView

The ouput getting is in the below image:

image

I have Problem on Both to get the proper output.

In Gallery View,

  • can not Change Background of Selected Item.and make it us rounded corner.
  • Selected Item comes to the center horizontal of the Screen Automatically.

In horizontal View,

  • More Complicated when the textView's number is large.
  • Can not find a way similar to On Click Item. if i have use switch case. the previous problem comes again.
+1  A: 

place this in drawables text_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    <item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/round" />
    <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/round" />
    <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/round_selected" />
    <item android:drawable="@drawable/round" />
</selector>

round.xml

    <?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle"> 
     <gradient android:startColor="#FFEF95" android:endColor="#FFEF95"   
            android:angle="270"/> 
<corners android:bottomRightRadius="14dp" android:bottomLeftRadius="14dp" 
     android:topLeftRadius="14dp" android:topRightRadius="14dp"/> 

</shape>

round_selected.xml

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle"> 
     <gradient android:startColor="#F6A110" android:centerColor="#FFEF95" android:endColor="#F6A110"   
            android:angle="270"/> 
<corners android:bottomRightRadius="14dp" android:bottomLeftRadius="14dp" 
     android:topLeftRadius="14dp" android:topRightRadius="14dp"/> 

</shape>

And here is the textview to inflate

 <TextView    
        android:id="@+id/perioxi_select" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Select Area"
         android:gravity="center_vertical|center_horizontal"
         android:background="@drawable/text_selector"
         android:minHeight="60dp"
         style="@style/FirstText"   
         android:layout_weight="1"
        />

Get the style too. should be placed inside res/valus/styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources> 
 <style name="FirstText"> 
        <item name="android:colorForeground">#f0f</item> 
        <item name="android:padding">4sp</item> 
        <item name="android:textSize">15sp</item> 
        <item name="android:textColor">#CC3300</item> 
        <item name="android:gravity">left</item> 
        <item name="android:typeface">monospace</item> 
        <item name="android:textStyle">bold</item> 
        <item name="android:colorBackground">#999</item> 
    </style> 
  </resources>
weakwire
minus rep? that's news..
weakwire
sorry. It happens mistakenly. i thought just upvote you. your answer is not accurate. But I got some Idea.Thanks. please edit your answer.
Praveen Chandrasekaran
it is accurate you just set android:background="@drawable/text_selector" to the element of your gallery (i suppose it's a TextView).. save round.xml round_selected.xml and text_selector.xml to /res/drawables and you're done.Rounded corners and when you press them change color.
weakwire
no you are wrong. you text_selector.xml shows all elements with the rounded corner background. But I would need to show just the selected item only have the rounded corner. I found the answer from android git kernal what are the states we have to define is in this link : http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/res/res/drawable/gallery_item_background.xml;h=c7eb7ea8b93c5022fe6710e87a552ca0fa47604f;hb=HEAD check it.
Praveen Chandrasekaran
well you just define another round_* for your needs..not that hard to adapt it to your needs since i posted all the code...
weakwire
i can not upvote you whether you didnt edit your answer.
Praveen Chandrasekaran
@weakwire: can you tell me when we select an item in `GalleryView` its comes to the center of the screen howto restrict it? I want to just be there where i click that item. How?
Praveen Chandrasekaran
Wild guess?override and Implement GalleryView and create a custom view but it's a long shot.in a recent project of mine i created a "Subject Selector" line.If that's the "control" you want to do ..I created it using a horizontal scrollview and Couple of TextViews.Textviews can be added to the Scrollview runtime so you don't really have a limit and can change it dynamically (A good reference to that is gridview example of the SDK)
weakwire