简体   繁体   English

如何使用具有一定百分比宽度的子项制作Android水平LinearLayout?

[英]How to make an Android horizontal LinearLayout with children that have a percentage width?

I've been searching this for a while and can't seem to quite grasp it. 我已经搜索了一段时间,但似乎不太了解它。 I know that this is probably done by using android:layout_weight , but I can't seem to figure it out. 我知道这可能是通过使用android:layout_weight ,但我似乎无法弄清楚。

What I want to accomplish is to have a horizontal LinearLayout that stretches the width of its parent's container and wraps the height of its child views. 我要实现的是有一个水平LinearLayout,它可以扩展其父容器的宽度并包装其子视图的高度。 This will be used for a music player for my app. 这将用于我的应用程序的音乐播放器。 For the child views, I want the following... 对于儿童,我需要以下内容...

Four ImageViews in a row, each set to 15% of the width (previous button, play/pause button, next button, and playlist button). 连续四个ImageView,每个View设置为宽度的15%(上一个按钮,播放/暂停按钮,下一个按钮和播放列表按钮)。 Then after these, I will have some type of view to represent the progress of the song you are listening to which will fill the remaining width (obviously 40% of the width). 然后,在这些之后,我将以某种类型的视图来表示您正在收听的歌曲的进度,该进度将填充剩余的宽度(显然是宽度的40%)。

My icons will be square, and I need the progress bar to be the same height as the icons. 我的图标将为方形,并且我需要进度条与图标的高度相同。 Below is a screenshot from my mobile site, and you can see what I'm trying to recreate by looking at the footer of the site. 以下是我的移动网站的屏幕截图,通过查看网站的页脚,您可以看到我正在尝试重新创建的内容。

在此处输入图片说明

Do it like this... total weightSum of 100, and you can make the desired distribution 这样做...总重量为100,您可以进行所需的分配

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="horizontal" 
   android:weightSum="100">

   BUTTON 1 layout_weight=15
   BUTTON 2 layout_weight=15
   BUTTON 3 layout_weight=15
   BUTTON 4 layout_weight=15

   ProgressBar layout_weight=40

</LinearLayout>

Also you can check this link about weight distribution http://developer.android.com/guide/topics/ui/layout/linear.html 您也可以查看有关体重分布的链接http://developer.android.com/guide/topics/ui/layout/linear.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM