代码之家  ›  专栏  ›  技术社区  ›  Praveen

Android上的文本库?

  •  8
  • Praveen  · 技术社区  · 14 年前

    我有一个画廊 TextView 在下图上实现分段控制器。我可以通过apidemo的画廊示例来实现它,但是我在画廊的外观和感觉上还比较落后。

    我要做的背景,选择/取消选择和选择的项目不会锥形到屏幕的中心。

    任何想法或文章都是最令人感激的。

    image http://www.freeimagehosting.net/uploads/cce47da969.png

    我试过用两种方法。那是:

    1. Gallery View
    2. horizontal ScrollView

    输出获取如下图所示:

    image http://www.freeimagehosting.net/uploads/b4c1be5924.png

    我在这两方面都有问题,无法获得正确的输出。

    在图库视图中,

    • 无法更改所选的背景 把它做成圆角。
    • 所选项目自动到达屏幕的中央水平位置。

    在水平视图中,

    • 更复杂的是 textView 的数字很大。
    • 找不到类似于单击项的方法。如果我有开关盒的话。前面的问题又出现了。
    1 回复  |  直到 13 年前
        1
  •  10
  •   weakwire    14 年前

    将其放入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>
    

    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>
    

    这是要充气的文本视图

     <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"
            />
    

    也要有风格。应该放在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>