[英]android linearlayout baseline align
I have 3 imageviews but since they overlap i wont make them clickable, i want make buttons on top of each imageview(but smaller). 我有3个imageview,但是由于它们重叠,所以我不会让它们可点击,我想在每个imageview的顶部都设置按钮(但要小一些)。
I know in RelativeLayout
there is easy way out using align_baseline
but it is very important that i use LinearLayout
for these images because they use layout_weight
我知道在
RelativeLayout
有使用align_baseline
简便方法,但是对这些图像使用LinearLayout
非常重要,因为它们使用layout_weight
And its important that button is connected with imageview, not just appearing on top of it 重要的是,按钮必须与imageview相关联,而不仅仅是出现在其顶部
And here is my code it might help 这是我的代码,可能会有所帮助
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/twitter"
android:layout_alignParentLeft="true"
android:orientation="vertical"
android:weightSum="3"
android:layout_marginBottom="25dp"
android:layout_alignParentTop="true" >
<ImageView
android:id="@+id/imgDis"
android:layout_weight="1"
android:layout_width="300dp"
android:layout_height="120dp"
android:layout_marginBottom="-20dp"
android:background="@drawable/img1" />
<ImageView
android:id="@+id/imgCal"
android:layout_weight="1"
android:layout_width="300dp"
android:layout_height="120dp"
android:layout_gravity="right"
android:layout_marginBottom="-25dp"
android:background="@drawable/img2"
android:paddingLeft="25dp" />
<ImageView
android:id="@+id/imgDe"
android:layout_weight="1"
android:layout_width="300dp"
android:layout_height="120dp"
android:background="@drawable/img3" />
</LinearLayout>
...
</RelativeLayout>
将图像垂直放置在另一个线性布局中,然后将该布局放置在主布局中,然后对该线性布局(而不是图像)进行调整
Here is your answer, while using weight
you must define 0dp
to height/width to view as per case. 这是您的答案,在使用
weight
,必须根据0dp
将高度/宽度定义为0dp
才能查看。
You want Button
on every Imageview
something like below? 您想要每个
Imageview
上的Button
如下所示吗?
I tried, check below xml: 我试过了,检查下面的xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="25dp"
android:orientation="vertical"
android:weightSum="6" >
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="5dp"
android:layout_weight="0.5"
android:text="button first" />
<ImageView
android:id="@+id/imgDis"
android:layout_width="300dp"
android:layout_height="0dp"
android:layout_marginTop="5dp"
android:layout_weight="1.5"
android:background="@drawable/logo" />
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="5dp"
android:layout_weight="0.5"
android:text="button first" />
<ImageView
android:id="@+id/imgCal"
android:layout_width="300dp"
android:layout_height="0dp"
android:layout_gravity="right"
android:layout_marginTop="5dp"
android:layout_weight="1.5"
android:background="@drawable/logo"
android:paddingLeft="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="5dp"
android:layout_weight="0.5"
android:text="button first" />
<ImageView
android:id="@+id/imgDe"
android:layout_width="300dp"
android:layout_height="0dp"
android:layout_marginTop="5dp"
android:layout_weight="1.5"
android:background="@drawable/logo" />
</LinearLayout>
</RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.