【问题标题】:Text Gallery on Android?Android上的文本库?
【发布时间】:2011-03-15 07:59:54
【问题描述】:

我有一个带有TextView 的图库,用于实现下图中的段控制器。我可以通过 ApiDemo 的 Gallery Example 实现它,但我在画廊的外观和感觉上落后了。

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

任何想法或文章都非常感谢。

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

我尝试使用 2 种方法。即:

  1. Gallery View
  2. horizontal ScrollView

得到的输出如下图:

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

我在两者上都有问题,无法获得正确的输出。

在图库视图中,

  • 无法更改选定对象的背景 Item.and 把它做成圆角。
  • 选中的项目会自动出现在屏幕的水平中心。

在水平视图中,

  • textView 的数量很大时会更复杂。
  • 找不到类似于 On Click Item 的方法。如果我有使用开关盒。上一个问题又来了。

【问题讨论】:

  • @praveen-chandrasekaran:很抱歉跑题了,但是您在按钮中添加了什么。它看起来不像 admob 的。
  • @Macarse:这就是 Google Adsense 移动版:查看此链接:google.com/mobileads/publisher_home.html
  • 嗨@Praveen,请分享这个画廊的代码。我也试过这个并应用下面但没有成功的所有东西请帮助....

标签: android gallery


【解决方案1】:

把它放在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>

这是要膨胀的文本视图

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

【讨论】:

  • 对不起。它发生错误。我以为只是支持你。你的回答不准确。但我有一些想法。谢谢。请编辑您的答案。
  • 准确地说,您只需将 android:background="@drawable/text_selector" 设置为画廊的元素(我想它是 TextView).. 保存 round.xml round_selected.xml 和 text_selector.xml到 /res/drawables 就完成了。圆角,当你按下它们时会改变颜色。
  • 不,你错了。你 text_selector.xml 显示所有元素的圆角背景。但我只需要显示所选项目只有圆角。我从 android git kernal 找到了我们必须定义的状态的答案在这个链接中:android.git.kernel.org/?p=platform/frameworks/… 检查它。
  • 好吧,你只需为你的需要定义另一个轮次_*。因为我发布了所有代码,所以让它适应你的需要并不难......
  • @weakwire:你能告诉我,当我们在GalleryView中选择一个项目时,它来到屏幕的中心如何限制它?我只想在我点击那个项目的地方。怎么样?
猜你喜欢
  • 2016-09-29
  • 1970-01-01
  • 1970-01-01
  • 2011-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多