[英]I have some problems with the XML layouts (android development).
I think I have some problems with a LinearLayout container. 我认为LinearLayout容器存在一些问题。 I do not know how to fix these problems:
我不知道如何解决这些问题:
I am a beginner to XML but I think the problem is in the second LinearLayout. 我是XML的初学者,但我认为问题出在第二个LinearLayout中。 I hope someone can help me out.
我希望有人能帮助我。
The code is here below: 代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
**<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
andriod:orientation="horizontal" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>**
<Button
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
</LinearLayout>
The problem I see when reading your xml file is that inside the main LinearLayout
you have 3 elements with the properties about the width and height as follows: 我在读取xml文件时看到的问题是,在主
LinearLayout
您具有3个元素,这些元素的宽度和高度属性如下:
android:layout_height="match_parent"
android:layout_width="match_parent"
which means you expect the elements to fill entirely the main LinearLayout
. 这意味着您希望元素完全填充主要的
LinearLayout
。 This is not going to work. 这是行不通的。 A linear layout has ordered not overlapping elements (
RelativeLayout
is there for that). 线性布局已排序不重叠的元素(
RelativeLayout
在那里)。 Since the main LinearLayout
is supposed to be oriented vertically, I suppose that for these three elements, you need to set the properties to match the whole width of main LinearLayout
and to be wrapped vertically, by setting these values: 由于应该将主要
LinearLayout
垂直放置,因此我想对于这三个元素,需要通过设置以下值来设置属性以匹配主要LinearLayout
的整个宽度并垂直包裹:
android:layout_height="wrap_content"
android:layout_width="match_parent"
You should apply these to the TextView
, LinearLayout
and Button
elements of second level. 您应该将它们应用于第二级的
TextView
, LinearLayout
和Button
元素。
如果您有重叠的图像视图,请尝试为其添加权重和/或更改宽度以使其与父视图不匹配,而仅包装内容。
请将andriod更改为android(第14行)
Your posted code has a typo. 您发布的代码有错字。 Your fix might be as simple as replacing the line:
您的修复可能就像替换该行一样简单:
andriod:orientation="horizontal"
with: 有:
android:orientation="horizontal"
Judging by the image you posted, I think you may have forgotten to add weights to occupy the free space in your Linearlayouts. 从发布的图像来看,我认为您可能已经忘记增加权重来占用Linearlayout中的可用空间。 Try this:
尝试这个:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
andriod:orientation="horizontal"
android:layout_weight="1" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
/>
</LinearLayout>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.