Android的Horizo​​ntalScrollView内容弹力 [英] Android HorizontalScrollView content Stretch

查看:271
本文介绍了Android的Horizo​​ntalScrollView内容弹力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些按钮的Horizo​​ntalScrollView,我试图伸展这些按钮来填补Horizo​​ntalScrollView的整个宽度,使他们能够出现有组织,彼此之间的间隔相等。这里是我的形象。

我想这4个按键被拉长了整个宽度!这里是我的code

 < Horizo​​ntalScrollView
    机器人:ID =@ + ID / items_Horizo​​ntalBar
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignBottom =@ + ID / VF
    机器人:背景=#8000
    机器人:fillViewport =真正的>    <的LinearLayout
        机器人:layout_width =match_parent
        机器人:layout_height =FILL_PARENT
        机器人:方向=横向>        <按钮
            机器人:layout_width =90dp
            机器人:layout_height =FILL_PARENT
            机器人:layout_margin =5DP
            机器人:背景=@机器人:彩色/透明
            机器人:drawableTop =@绘制/ RSS
            机器人:文字=轻
            机器人:文字颜色=@彩色/ green_color
            机器人:TEXTSIZE =20SP/>        <按钮
            机器人:layout_width =90dp
            机器人:layout_height =FILL_PARENT
            机器人:layout_margin =5DP
            机器人:背景=@机器人:彩色/透明
            机器人:drawableTop =@绘制/ RSS
            机器人:文字=门
            机器人:文字颜色=@彩色/ green_color
            机器人:TEXTSIZE =20SP/>        <按钮
            机器人:layout_width =90dp
            机器人:layout_height =FILL_PARENT
            机器人:layout_margin =5DP
            机器人:背景=@机器人:彩色/透明
            机器人:drawableTop =@绘制/ RSS
            机器人:文字=报警
            机器人:文字颜色=@彩色/ green_color
            机器人:TEXTSIZE =20SP/>        <按钮
            机器人:layout_width =90dp
            机器人:layout_height =FILL_PARENT
            机器人:layout_margin =5DP
            机器人:背景=@机器人:彩色/透明
            机器人:drawableTop =@绘制/ RSS
            机器人:文字=窗口
            机器人:文字颜色=@彩色/ green_color
            机器人:TEXTSIZE =20SP/>
    < / LinearLayout中>
< / Horizo​​ntalScrollView>


解决方案

有关平等的分配,将 weightSum 母公司的价值,并分配 layout_weight 以它的孩子。

有关4相同大小的按钮,添加的android:weightSum =1到的LinearLayout。对于每一个设置按钮的android:layout_width =0dp,然后添加的android:layout_weight =0.25

这是在code发生什么,但根据不同的视图中,平均分配权重的在Eclipse GUI按钮也有帮助。

不过, Horizo​​ntalScrollView 只能承载一个直接的孩子,我想知道这个布局结构...

I have a HorizontalScrollView with some buttons, I am trying to stretch these buttons to fill the whole width of the HorizontalScrollView so that they can appear organized and equally spaced between each others. Here is the Image which I have.

I want these 4 buttons to be stretched over the whole width! here is my code

    <HorizontalScrollView
    android:id="@+id/items_HorizontalBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/vf"
    android:background="#80000000"
    android:fillViewport="true" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >

        <Button
            android:layout_width="90dp"
            android:layout_height="fill_parent"
            android:layout_margin="5dp"
            android:background="@android:color/transparent"
            android:drawableTop="@drawable/rss"
            android:text="Light"
            android:textColor="@color/green_color"
            android:textSize="20sp" />

        <Button
            android:layout_width="90dp"
            android:layout_height="fill_parent"
            android:layout_margin="5dp"
            android:background="@android:color/transparent"
            android:drawableTop="@drawable/rss"
            android:text="Door"
            android:textColor="@color/green_color"
            android:textSize="20sp" />

        <Button
            android:layout_width="90dp"
            android:layout_height="fill_parent"
            android:layout_margin="5dp"
            android:background="@android:color/transparent"
            android:drawableTop="@drawable/rss"
            android:text="Alarms"
            android:textColor="@color/green_color"
            android:textSize="20sp" />

        <Button
            android:layout_width="90dp"
            android:layout_height="fill_parent"
            android:layout_margin="5dp"
            android:background="@android:color/transparent"
            android:drawableTop="@drawable/rss"
            android:text="Window"
            android:textColor="@color/green_color"
            android:textSize="20sp" />
    </LinearLayout>
</HorizontalScrollView>

解决方案

For equal distributions, set the weightSum value of the parent, and assign layout_weight to its children.

For 4 equal sized buttons, add android:weightSum="1" to the LinearLayout. For each of the buttons set android:layout_width="0dp", then add android:layout_weight="0.25".

This is what occurs in the code but depending on the View, the "Distribute Weights Evenly" button in the Eclipse GUI can also help.

However, HorizontalScrollView can only host one direct child, I wonder about the structure of this layout...

这篇关于Android的Horizo​​ntalScrollView内容弹力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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