[英]How to make application responsive for all android devices?
I am creating one application and I want my application to open without any issue with view,I tried to use weightsum attribute for that but I do not know why it shows different views all time in different devices,check this.. 我正在创建一个应用程序,我希望我的应用程序打开没有任何问题的视图,我试图使用权限属性,但我不知道为什么它在不同的设备中显示不同的视图,检查这..
<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>
in bluestack it looks like this 在bluestack中它看起来像这样
Change android:layout_width
and android:layout_height
to "match_parent"
of LinearLayout
. 将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>
Give match_parent width and height in container 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>
Also, you are using weight incorrectly. 此外,您正在使用不正确的重量。
Weight sum and weight is used to divide screen portion equally between some elements. 重量和和重量用于在一些元素之间平均划分屏幕部分。 So if you give weightsum = "3" in container layout, and its 3 children layout mention weight="1", then all three children uses up 33.33% part of container layout. 因此,如果您在容器布局中给予weightsum =“3”,并且其3个子布局提到weight =“1”,则所有三个子容器占用容器布局的33.33%部分。 And at that time width and height are kept as 0 dp according to container layout's orientation. 此时宽度和高度根据容器布局的方向保持为0 dp。
Hi Johnson this example may help you. 嗨约翰逊这个例子可能会帮助你。
<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.