Android上的文字库?

Pra*_*een 8 android gallery

我有一个图库,TextView用于在下面的图像上实现分段控制器.我可以通过ApiDemo的Gallery示例来实现它,但我对画廊的外观和感觉有所滞后.

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

任何想法或文章都非常感激.

图片http://www.freeimagehosting.net/uploads/cce47da969.png

我试图使用2种方法.那是:

  1. Gallery View
  2. horizontal ScrollView

输出获取如下图所示:

图片http://www.freeimagehosting.net/uploads/b4c1be5924.png

我有两个问题,以获得正确的输出.

在图库视图中

  • 无法更改所选项目的背景,并使其成为圆角.
  • 选定项目自动进入屏幕的中心水平.

在水平视图中,

  • textView数量很大时更复杂.
  • 找不到类似于On Click Item的方法.如果我使用开关盒.先前的问题又来了.

wea*_*ire 10

将它放在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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

这是膨胀的textview

 <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"
        />
Run Code Online (Sandbox Code Playgroud)

获得风格.应该放在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>
Run Code Online (Sandbox Code Playgroud)

  • 不,你错了.text_selector.xml显示所有带圆角背景的元素.但我需要只显示所选项目的圆角.我从android git kernal找到了答案我们必须在这个链接中定义的状态是什么: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检查它. (2认同)
  • 好吧,你只需要为你的需要定义另一个round_*因为我发布了所有代码,所以很难适应你的需求... (2认同)