Text Gallery on Android?

后端 未结 1 515
天命终不由人
天命终不由人 2020-12-04 22:57

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

相关标签:
1条回答
  • 2020-12-04 23:54

    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>
    
    0 讨论(0)
提交回复
热议问题