【发布时间】:2014-04-08 23:56:35
【问题描述】:
我是 android 编程新手,我正在尝试了解 android 架构以及应用程序是如何围绕它构建的。
因此,目前还没有现实世界对此的需求。我正在做一些实验来学习这些东西。我想要的是 3 个不同的视图,TextView、EditText 和 Button,它们水平相邻。为了实现这一点,这是我正在使用的 activity_main.xml:-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<EditText android:id="@+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_to_appear_on_button" />
</LinearLayout>
在运行具有 setContentView(R.layout.activity_main); 的 MainActivity.java 时,在 onCreate() 中,我在屏幕上获得了 TextView 和 EditText 小部件,它们水平相邻,但没有 Button .我想知道为什么?
奇怪的是,我观察到里面的最后一个元素
<LinearLayout>..</LinearLayout>是从屏幕上消失的那个。因此,如果<Button .. />与<TextView .. />交换,那么它的<TextView>元素现在将不会在屏幕上可见。
请解释一下我在这里遗漏了什么。
我正在模拟器上运行 MainActivity.java 并使用 Eclipse 作为我的 IDE,如果这些信息有帮助的话。
【问题讨论】:
-
从developer.android.com/guide/topics/ui/layout/linear.html#Weight了解LinearLayout权重
-
@b1izzard 感谢您指出资源。这很有帮助。
标签: android android-layout android-view android-xml