Android LinerarLayout的内容没有所需的宽度
您好,我是Android开发的新手,尤其是XML 我希望EditText和按钮填充屏幕宽度,但当在模拟器上方运行代码时,它们显示居中,但仅填充大约一半的屏幕宽度。我怎样才能改变这一点?我做错了什么? 谢谢这应该可以:Android LinerarLayout的内容没有所需的宽度,android,xml,android-linearlayout,android-xml,Android,Xml,Android Linearlayout,Android Xml,您好,我是Android开发的新手,尤其是XML 我希望EditText和按钮填充屏幕宽度,但当在模拟器上方运行代码时,它们显示居中,但仅填充大约一半的屏幕宽度。我怎样才能改变这一点?我做错了什么? 谢谢这应该可以: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_wid
<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:background="@drawable/hintergrund"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/display"
android:orientation="vertical"
>
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
/>
<Button
android:layout_width="fill_parent"
android:text="bla"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/ergebnis"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</LinearLayout>
告诉我它是怎么回事。在你的第二个
线性布局中
你将背景设置为@drawable/display
-图像是否实际填满了屏幕宽度?background diplay.png是一个可拉伸的.9.png文件,所以我想它应该拉伸到屏幕尺寸?对不起,也许我的问题不清楚。你在布局中看到了什么?背景拉伸是否适合屏幕?我这样问是因为第一个LinearLayout
是第二个LinearLayout
的父对象,第二个LinearLayout
是EditText
、按钮和TextView
的父对象。布局参数,如match\u parent
直接引用“parent”。如果您的背景可绘制文件未延伸至全屏宽度,则可能是因为第二个(内部)LinearLayout
自动调整为可绘制文件的大小,这可能解释了EditText
和按钮的宽度问题。背景图像确实会拉伸,但是屏幕的边框有很小的边距,这些边距充满了外部线条布局的图像。您可以在这个屏幕截图上看到,@drawable/display
顶部和侧面的小间隙是由于外部线性布局
(与所有视图一样)设置了填充
可能默认为3dp或4或5。如果您想消除这些间隙,可以将其减少到0dp。遗憾的是,我对您在使用编辑文本
和按钮
时遇到的问题没有任何进一步的想法,对不起。谢谢您的回答,我恐怕这对我不起作用。首先,我手动更改了代码并尝试了一下,但没有成功。然后我也复制了你的完整代码,但结果是一样的。有没有可能是background display.png有问题?它是一个可拉伸的.9.png文件。。。
<?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="match_parent"
android:backgroun="@drawable/hintergrund"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/display"
android:orientation="vertical" >
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="bla" />
<TextView
android:id="@+id/ergebnis"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>