I have three imageViews There I want to set all these ImageView
into one line. I have pasted my current xml code below.
我有三个imageViews我想将所有这些ImageView设置为一行。我已粘贴下面的当前xml代码。
<RelativeLayout
android:id="@+id/myFragement"
android:layout_width="wrap_content"
android:layout_height="306dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="44dp"
android:layout_weight="1.77"
android:orientation="horizontal" >
</RelativeLayout>
<ImageView
android:id="@+id/login_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/login_non_click" />
<ImageView
android:id="@+id/comapre_now_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/compare_now_non_click_state" />
<ImageView
android:id="@+id/search_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/comapre_now_button"
android:src="@drawable/search_non_click" />
</RelativeLayout>
After i have sloved. posted my App's image i think this is helpful all
在我解散之后。发布我的应用程序的图像我认为这是有用的
After editing i have posted my App's all Xml code i think this is helpful all.
编辑后,我发布了我的应用程序的所有Xml代码,我认为这是有用的。
<RelativeLayout
android:id="@+id/myFragement"
android:layout_width="wrap_content"
android:layout_height="306dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="44dp"
android:layout_weight="1.77"
android:orientation="horizontal" >
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:weightSum="3" >
<ImageView
android:id="@+id/login_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/login_non_click" />
<ImageView
android:id="@+id/comapre_now_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/compare_now_non_click_state" />
<ImageView
android:id="@+id/search_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/search_non_click" />
</LinearLayout>
2 个解决方案
#1
4
The answer that fida gave should provide what you want (or close to it). That is assuming that you want them all to take up 1/3 of the screen. Otherwise, you can eliminate the weight
property and use margin between the View
s or use empty View
s between each of them and give an appropriate weight
.
fida给出的答案应该提供你想要的(或接近它)。假设您希望它们全部占据屏幕的1/3。否则,您可以消除权重属性并在视图之间使用边距,或者在每个视图之间使用空视图并给出适当的权重。
The reason you aren't getting them in a horizontal layout is because you have android:layout_width="match_parent"
for the first ImageView
so I'm guessing that is taking up the whole width. They should probably be android:layout_width="wrap_content"
. Also, for your last one, you have android:layout_below="@+id/comapre_now_button"
which will obviously put it below the View
with that id
.
你没有在水平布局中得到它们的原因是因为你有第一个ImageView的android:layout_width =“match_parent”所以我猜这是占据了整个宽度。它们应该是android:layout_width =“wrap_content”。另外,对于你的最后一个,你有android:layout_below =“@ + id / comapre_now_button”,这显然会把它放在具有该id的View下面。
Assuming you want that in the center, you probably want android:layout_centerHorizontal="true"
or android:layout_toRightOf="@id/someId"
or android:layout_toLeftOf="id/someId"
假设你想要在中心,你可能想要android:layout_centerHorizontal =“true”或android:layout_toRightOf =“@ id / someId”或android:layout_toLeftOf =“id / someId”
Also, not the problem, but RelativeLayout
doesn't have an orientation
or weight
property.
此外,不是问题,但RelativeLayout没有方向或权重属性。
#2
9
Try like below, put the ImageView
s in an inner LinearLayout
with horizontal orientation
:
尝试如下,将ImageViews放在水平方向的内部LinearLayout中:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:weightSum="3" >
<ImageView
android:id="@+id/login_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/login_non_click" />
<ImageView
android:id="@+id/comapre_now_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/compare_now_non_click_state" />
<ImageView
android:id="@+id/search_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/search_non_click" />
</LinearLayout>
#1
4
The answer that fida gave should provide what you want (or close to it). That is assuming that you want them all to take up 1/3 of the screen. Otherwise, you can eliminate the weight
property and use margin between the View
s or use empty View
s between each of them and give an appropriate weight
.
fida给出的答案应该提供你想要的(或接近它)。假设您希望它们全部占据屏幕的1/3。否则,您可以消除权重属性并在视图之间使用边距,或者在每个视图之间使用空视图并给出适当的权重。
The reason you aren't getting them in a horizontal layout is because you have android:layout_width="match_parent"
for the first ImageView
so I'm guessing that is taking up the whole width. They should probably be android:layout_width="wrap_content"
. Also, for your last one, you have android:layout_below="@+id/comapre_now_button"
which will obviously put it below the View
with that id
.
你没有在水平布局中得到它们的原因是因为你有第一个ImageView的android:layout_width =“match_parent”所以我猜这是占据了整个宽度。它们应该是android:layout_width =“wrap_content”。另外,对于你的最后一个,你有android:layout_below =“@ + id / comapre_now_button”,这显然会把它放在具有该id的View下面。
Assuming you want that in the center, you probably want android:layout_centerHorizontal="true"
or android:layout_toRightOf="@id/someId"
or android:layout_toLeftOf="id/someId"
假设你想要在中心,你可能想要android:layout_centerHorizontal =“true”或android:layout_toRightOf =“@ id / someId”或android:layout_toLeftOf =“id / someId”
Also, not the problem, but RelativeLayout
doesn't have an orientation
or weight
property.
此外,不是问题,但RelativeLayout没有方向或权重属性。
#2
9
Try like below, put the ImageView
s in an inner LinearLayout
with horizontal orientation
:
尝试如下,将ImageViews放在水平方向的内部LinearLayout中:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:weightSum="3" >
<ImageView
android:id="@+id/login_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/login_non_click" />
<ImageView
android:id="@+id/comapre_now_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/compare_now_non_click_state" />
<ImageView
android:id="@+id/search_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/search_non_click" />
</LinearLayout>