的LinearLayout:layout_gravity ="底部"不工作水平的LinearLayout [英] LinearLayout: layout_gravity="bottom" not working on Horizontal LinearLayout

查看:111
本文介绍了的LinearLayout:layout_gravity ="底部"不工作水平的LinearLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,首先,我找遍了所有的互联网,但没有人有这样类似的问题。所以,我要的是有3 textViews,底部与屏幕和相同的宽度一致。这里是再presenting的图像是我想要的:

Ok, First of all, I searched all the internet, but nobody has a similar problem like this. So, all I want is to have 3 textViews, bottom aligned with the screen and with the same width. Here is an image representing what I want:

和这里是我的code:

And here is my code:

 <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent">
 <LinearLayout 
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true">

      <TextView 
           android:text="@string/help_1"
           android:layout_weight="0.33"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:background="@drawable/mynicebg1"

           android:layout_gravity="bottom"/>

      <TextView 
           android:text="@string/help_2"
           android:layout_weight="0.33"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:background="@drawable/mynicebg2"

           android:layout_gravity="bottom"/>

      <TextView 
           android:text="@string/help_3"
           android:layout_weight="0.33"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:background="@drawable/mynicebg3"

           android:layout_gravity="bottom"/>

 </LinearLayout>
 </RelativeLayout>

那么,它的工作原理,当3 textViews具有相同的高度,但是当它们的大小不同,我得到以下结果:

Well, it works when the 3 textViews have the same height, but when their size differ, I get the following result:

另一个奇怪的现象是,当我设置的最大文本的layout_gravity为中心垂直,我得到以下结果:

Another strange behavior, is that when I set the layout_gravity of the biggest text to "center-vertical", I get the following result:

所以,很显然,我疯了,想另外一个组合,带中央垂直,但是毫无效果,因为我想最初:

So obviously, I went crazy and tried another combinations with center-vertical, but nothing worked as I wanted initially:

那么,如何解决这个任何提示?

So, any tips on how to solve this?

推荐答案

所有的其他的答案是错的。要点:

The Correct Answer

All the other answers are wrong. The important points:

  1. 您不需要 RelativeLayout的。你可以只用一个的LinearLayout
  2. 做到这一点
  3. (并不重要,但我猜你不知道),你的权重并不需要总结为1,你可以将它们全部给任何相等的值(例如1)。
  4. 在关键的事情是你需要的 安卓baselineAligned =假 。我其实只翻翻的LinearLayout 来源发现这一点。它是在文档,但他们不提,这是的默认情况下!
  1. You don't need RelativeLayout. You can do this with just a LinearLayout.
  2. (Not critical but I guess you didn't know) Your weights don't need to sum to 1, you can just set them all to any equal value (e.g. 1).
  3. The critical thing is you need android:baselineAligned="false". I actually only found this by looking through the LinearLayout source. It is in the docs but they don't mention that it is on by default!

总之,这里是code:

Anyway, here is the code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:baselineAligned="false">
      <TextView 
           android:text="dfg dfg dfg dfg dfg dfg dfg dfg dfg dfg dfg dfg dfg dfg dfg dfg dfg dfg dfg dfg"
           android:layout_weight="1"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:background="#eeffee"
           android:layout_gravity="bottom"/>

      <TextView 
           android:text="asd asd asd asd asd asd asd asd asd asd"
           android:layout_weight="1"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:background="#eeeeff"
           android:layout_gravity="bottom"/>


      <TextView 
           android:text="qweoiu qweoiuqwe oiqwe qwoeiu qweoiu qweoiuq weoiuqw eoiquw eoiqwue oqiweu qowieu qowieu qoiweu qowieu qowieu qowieu qowieu qoiweu qowieu qoiwue "
           android:layout_weight="1"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:background="#ffeeee"
           android:layout_gravity="bottom"/>

 </LinearLayout>

和它的外观:

这篇关于的LinearLayout:layout_gravity =&QUOT;底部&QUOT;不工作水平的LinearLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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