与Horizo​​ntalScrollView-安卓水平菜单 [英] Horizontal menu with HorizontalScrollView-android

查看:167
本文介绍了与Horizo​​ntalScrollView-安卓水平菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个水平的菜单我要实现。而这 菜单应与左,右箭头这样的福克斯新闻应用程序<水平平滑滚动href="https://market.android.com/details?id=com.foxnews.android">https://market.android.com/details?id=com.foxnews.android与第一个应用程序的屏幕截图。

通过使用谷歌等后期在这个论坛上,我用horizo​​ntalScrollView来实现它,但不知道如何与箭头设置左,右透明图像,表明有更多的元素向左或向右取决于滚动。

无论我codeD,实现滚动运动,但其缓慢而艰难地显示左眼和右眼图像箭头。

请告诉我,如果你对此有什么解决办法。

这个布局我使用

 &LT; Horizo​​ntalScrollView
    机器人:ID =@ + ID / hor_svID
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =35dip
    机器人:滚动条=无
    机器人:fillViewport =假
    机器人:可聚焦=假
    机器人:背景=@可绘制/ submenu_bg&GT;
    &LT;的LinearLayout
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =FILL_PARENT
        机器人:方向=横向
        机器人:可聚焦=假
        机器人:后台=#FFFFFF
        机器人:重力=中心&GT;
        &LT; TextView的机器人:ID =@ + ID / TechnologyTxtVId
                机器人:文本=科技
                机器人:文字颜色=#342D7E
                机器人:TEXTSIZE =12SP
                机器人:TEXTSTYLE =黑体
                机器人:重力=中心
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT&GT;&LT; / TextView的&GT;
        &LT; TextView的机器人:ID =@ + ID / SportsTxtVId
                机器人:文本=SPORTS
                机器人:文字颜色=#342D7E
                机器人:TEXTSTYLE =黑体
                机器人:TEXTSIZE =12SP
                机器人:重力=中心
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_width =WRAP_CONTENT
                机器人:以下属性来=15dip&GT;&LT; / TextView的&GT;
        &LT; TextView的机器人:ID =@ + ID / EntntTxtVId
                机器人:文本=娱乐
                机器人:TEXTSTYLE =黑体
                机器人:以下属性来=15dip
                机器人:TEXTSIZE =12SP
                机器人:重力=中心
                机器人:文字颜色=#342D7E
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT&GT;&LT; / TextView的&GT;
        &LT; TextView的机器人:ID =@ + ID / LocalTxtVId
                机器人:文本=本地
                机器人:TEXTSTYLE =黑体
                机器人:以下属性来=15dip
                机器人:TEXTSIZE =12SP
                机器人:文字颜色=#342D7E
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT&GT;&LT; / TextView的&GT;
        &LT; TextView的机器人:ID =@ + ID / WorldTxtVId
                机器人:文字=世界
                机器人:TEXTSTYLE =黑体
                机器人:TEXTSIZE =12SP
                机器人:以下属性来=15dip
                机器人:重力=中心
                机器人:文字颜色=#342D7E
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT&GT;&LT; / TextView的&GT;
        &LT; TextView的机器人:ID =@ + ID / FeaturesTxtVId
                机器人:文本=特点
                机器人:TEXTSTYLE =黑体
                机器人:TEXTSIZE =12SP
                机器人:以下属性来=15dip
                机器人:重力=中心
                机器人:文字颜色=#342D7E
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT&GT;&LT; / TextView的&GT;
        &LT; TextView的机器人:ID =@ + ID / RecentTxtVId
                机器人:文本=近期
                机器人:TEXTSTYLE =黑体
                机器人:TEXTSIZE =12SP
                机器人:以下属性来=15dip
                机器人:重力=中心
                机器人:文字颜色=#342D7E
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT&GT;&LT; / TextView的&GT;
    &LT; / LinearLayout中&GT;
&LT; / Horizo​​ntalScrollView&GT;
 

解决方案

我不知道,你正在使用这个确切的情况下,但你应该在的LinearLayout更改为相对的(它在一个简单的变化您textViews加入以下内容:

  • 对于第一个文本:

    安卓layout_alignParentLeft =真正的

  • 在接下来的文章

    安卓layout_toRightOf =@ ID / previous_text

如果您是嵌入这里面其他LinearLayouts,也许你也应该重新考虑是否可以使用relativeLayouts有太多根据下面提供的高效布局原则:

http://developer.android.com/resources/articles/布局花招efficiency.html

让我知道如果这有助于一些荣誉;) 谢谢,祝你好运!

This is one horizontal menu I have to implement .And this menu should scroll horizontally smoothly with left and right arrow like this Fox News application https://market.android.com/details?id=com.foxnews.android with the first app screen shot.

By using google and other post on this forum I used horizontalScrollView to achieve it,but don't know how to set left and right transparent images with arrow to indicate that there are more element to left or right depending on scroll.

Whatever I coded ,achieved scrolling movement but its slow and struggling to show left and right images with arrow.

Kindly tell me if you have any solution on this.

This layout I am using

<HorizontalScrollView
    android:id="@+id/hor_svID"
    android:layout_width="wrap_content"
    android:layout_height="35dip"
    android:scrollbars="none"
    android:fillViewport="false"
    android:focusable="false"
    android:background="@drawable/submenu_bg">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        android:focusable="false"
        android:background="#FFFFFF"
        android:gravity="center">
        <TextView android:id="@+id/TechnologyTxtVId" 
                android:text="TECHNOLOGY"   
                android:textColor="#342D7E"
                android:textSize="12sp"
                android:textStyle="bold"
                android:gravity="center"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"></TextView>
        <TextView android:id="@+id/SportsTxtVId" 
                android:text="SPORTS" 
                android:textColor="#342D7E" 
                android:textStyle="bold"
                android:textSize="12sp"
                android:gravity="center"
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content" 
                android:paddingLeft="15dip"></TextView> 
        <TextView android:id="@+id/EntntTxtVId" 
                android:text="ENTERTAINMENT"    
                android:textStyle="bold"
                android:paddingLeft="15dip"
                android:textSize="12sp"
                android:gravity="center"
                android:textColor="#342D7E"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"></TextView>
        <TextView android:id="@+id/LocalTxtVId" 
                android:text="LOCAL"    
                android:textStyle="bold"
                android:paddingLeft="15dip"
                android:textSize="12sp"
                android:textColor="#342D7E"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"></TextView>        
        <TextView android:id="@+id/WorldTxtVId" 
                android:text="WORLD"    
                android:textStyle="bold"
                android:textSize="12sp"
                android:paddingLeft="15dip"
                android:gravity="center"
                android:textColor="#342D7E"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"></TextView>    
        <TextView android:id="@+id/FeaturesTxtVId" 
                android:text="FEATURES" 
                android:textStyle="bold"
                android:textSize="12sp"
                android:paddingLeft="15dip"
                android:gravity="center"
                android:textColor="#342D7E"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"></TextView>        
        <TextView android:id="@+id/RecentTxtVId" 
                android:text="RECENT"   
                android:textStyle="bold"
                android:textSize="12sp"
                android:paddingLeft="15dip"
                android:gravity="center"
                android:textColor="#342D7E"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"></TextView>                                
    </LinearLayout>                                     
</HorizontalScrollView>

解决方案

I don't know the exact context in which you are using this, but you should probably change the LinearLayout to a relative one (it's a simple change in to your textViews adding the following:

  • For the first text:

    android:layout_alignParentLeft="true"

  • For the next texts

    android:layout_toRightOf="@id/previous_text"

If you are embedding this inside other LinearLayouts, perhaps you should also reconsider whether you can use relativeLayouts there too as per the efficient layout guidelines provided below:

http://developer.android.com/resources/articles/layout-tricks-efficiency.html

Let me know if this helps with some kudos ;) Thanks and good luck!

这篇关于与Horizo​​ntalScrollView-安卓水平菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆