8

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 http://www.freeimagehosting.net/uploads/cce47da969.png

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 http://www.freeimagehosting.net/uploads/b4c1be5924.png

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.
Praveen
  • 90,477
  • 74
  • 177
  • 219
  • @praveen-chandrasekaran: Sorry for the offtopic but what is your add in the button. It doesn't look like admob's. – Macarse Jul 13 '10 at 13:34
  • 1
    @Macarse: thats Google Adsense for mobile: check this link: http://www.google.com/mobileads/publisher_home.html – Praveen Jul 13 '10 at 13:40
  • Hi @Praveen, Plz share the code of this gallery. I am also tried this and apply all things which are below but not succeeded plz help.... – AndroidDanger Aug 04 '11 at 12:25

1 Answers1

10

place this in drawables text_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <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
  • 9,284
  • 8
  • 53
  • 78
  • 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 Jul 14 '10 at 16:21
  • 1
    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 Jul 14 '10 at 16:47
  • 2
    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 Jul 14 '10 at 17:40
  • 2
    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 Jul 14 '10 at 18:10
  • @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 Jul 23 '10 at 13:35
  • 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 Jul 24 '10 at 03:56