【发布时间】:2014-05-27 13:29:36
【问题描述】:
我正在关注this 教程来学习 Android 开发。我遇到了一个关于如何在屏幕上显示控件的问题。
如果您查看该教程中的屏幕截图,您会发现所有 UI 元素一个接一个地以堆叠方式显示在屏幕上。但是当我这样做时,它看起来像这样。
肖像
如您所见,可见屏幕空间中只显示了几个元素。其余部分位于屏幕右侧。如果我将屏幕转为横向,它们就在那里。
这是我的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" >
<TextView
android:id="@+id/main_textview"
android:text="@string/textview"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/main_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="@string/button" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:src="@drawable/ic_launcher" />
</LinearLayout>
<EditText
android:id="@+id/main_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:hint="@string/hint" />
<ListView
android:id="@+id/main_listview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="20dp" />
</LinearLayout>
一切都按照教程所述编写。
然而,在本教程中,他们使用模拟器来运行它。我使用Micromax A74 Canvas 进行测试。但是我在同一个模拟器中运行了该应用程序,但我仍然遇到了这个确切的问题。
谁能告诉我我可能做错了什么以及如何纠正它?
谢谢。
【问题讨论】:
-
将
android:orientation="vertical"设置为您的LinearLayout -
你的父母
LinearLayout没有orientation