布局崩溃 - 如何使其均匀/对齐?
请查看设计师的图片:
现在看看我得到了什么:
这是我的布局:
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="@drawable/nav_back">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
android:drawableTop="@drawable/home"
android:background="@drawable/nav_selected"
android:layout_weight="1"
android:textColor="#FFF"
android:textSize="10dp"
android:text="Home"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
android:drawableTop="@drawable/home_g"
android:background="@drawable/nav_back"
android:layout_weight="1"
android:textColor="#FFF"
android:textSize="10dp"
android:text="This is long string that pushes layout"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
android:drawableTop="@drawable/available_g"
android:background="@drawable/nav_back"
android:layout_weight="1"
android:textColor="#FFF"
android:textSize="10dp"
android:text="Available"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
android:drawableTop="@drawable/completed_g"
android:background="@drawable/nav_back"
android:layout_weight="1"
android:textColor="#FFF"
android:textSize="10dp"
android:text="Completed"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
android:drawableTop="@drawable/mail_g"
android:background="@drawable/nav_back"
android:layout_weight="1"
android:textColor="#FFF"
android:textSize="10dp"
android:text="Mail"/>
</LinearLayout>
问题。我该如何:
确保无论如何 - 屏幕分解为 5 个偶数段 - 所以所有按钮,无论里面有文本。
如果一个按钮将布局向下推 - 我如何确保其他按钮也填充该垂直空间?就像主页按钮并不完全向下一样 - 您可以看到 nav_selected 结束的位置
我有按照谷歌格式的3种尺寸的PNG图标。如果可能的话,我希望为 drawableTop 提供一些填充,以便图标在我的屏幕上看起来更小 - 更接近设计师屏幕的外观。
谢谢!
Please see designer's picture:
Now see what I'm getting:
Here is my layout:
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="@drawable/nav_back">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
android:drawableTop="@drawable/home"
android:background="@drawable/nav_selected"
android:layout_weight="1"
android:textColor="#FFF"
android:textSize="10dp"
android:text="Home"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
android:drawableTop="@drawable/home_g"
android:background="@drawable/nav_back"
android:layout_weight="1"
android:textColor="#FFF"
android:textSize="10dp"
android:text="This is long string that pushes layout"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
android:drawableTop="@drawable/available_g"
android:background="@drawable/nav_back"
android:layout_weight="1"
android:textColor="#FFF"
android:textSize="10dp"
android:text="Available"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
android:drawableTop="@drawable/completed_g"
android:background="@drawable/nav_back"
android:layout_weight="1"
android:textColor="#FFF"
android:textSize="10dp"
android:text="Completed"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
android:drawableTop="@drawable/mail_g"
android:background="@drawable/nav_back"
android:layout_weight="1"
android:textColor="#FFF"
android:textSize="10dp"
android:text="Mail"/>
</LinearLayout>
Questions. How do I:
Make sure no matter what - screen broken down to 5 even segments - so all buttons even no matter text inside.
If one button pushes layout down - how do I make sure other buttons fill that vertical space as well? Like home button is not all way down - you can see where nav_selected ends
I have icons in PNG in 3 sizes as per google format. I want to have some padding for drawableTop if possible so icons look smaller on my screen - closer to what designers screen look.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在此页面上有关 LinearLayouts 的部分中了解有关layout_weight的内容。这是您要用来使所有视图具有相同宽度的属性。我不太熟悉它的实现,但我认为当你这样做时,你可能不希望将宽度设置为wrap_content。
编辑:
这似乎是你想做的。
Read about layout_weight on this page in the section about LinearLayouts. That is the attribute you're going to want to use to get the views to all get the same width. I am not super familiar with its implementation but I would think you probably wont want width set to wrap_content when you do it that way.
Edit:
This seems like what you want to do.
或者,您可以使用 GridView(甚至 ListView、Gallery)并创建简单的适配器,您将在其中重写 getView() 方法来膨胀您的布局。我认为该布局非常容易创建,并且每个按钮都是相同的。此外,如果元素超过 5 个,您将能够滚动。
Alternatively, you can use GridView ( or even ListView, Gallery) and create simple adapter, where you will override getView() method to inflate your layout. I think that layout is pretty easy to create and it will be the same for each button. In addition, you'll be able to scroll if there's more than 5 elements.