[英]How to make application responsive for all android devices?
我正在创建一个应用程序,我希望我的应用程序打开没有任何问题的视图,我试图使用权限属性,但我不知道为什么它在不同的设备中显示不同的视图,检查这..
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/backgroundgd"
android:weightSum="100.0"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:background="@drawable/another"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:background="@drawable/secondpart"
/>
</LinearLayout>
在bluestack中它看起来像这样
将android:layout_width
和android:layout_height
更改为LinearLayout
"match_parent"
。
<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:orientation="vertical"
android:background="@drawable/backgroundgd"
android:weightSum="100.0">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_cntent"
android:text="@string/hello_world"
android:background="@drawable/another"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:background="@drawable/secondpart"
/>
</LinearLayout>
在容器LinearLayout中给出match_parent的宽度和高度:
<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:orientation="vertical"
android:background="@drawable/backgroundgd"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:background="@drawable/another"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:background="@drawable/secondpart"
/>
</LinearLayout>
此外,您正在使用不正确的重量。
重量和和重量用于在一些元素之间平均划分屏幕部分。 因此,如果您在容器布局中给予weightsum =“3”,并且其3个子布局提到weight =“1”,则所有三个子容器占用容器布局的33.33%部分。 此时宽度和高度根据容器布局的方向保持为0 dp。
嗨约翰逊这个例子可能会帮助你。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="5">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="2" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.