我有一个问题,使两个图像视图在同一条线上。我希望其中一个图像视图(imageyourfriends)在左边对齐,而另一个(imageyourfriendrequests)在右边。我一直在尝试不同的方法,但没有一种可行。到目前为止,我有这段代码(但我的一个图像视图在另一个下方)
<RelativeLayout
android:id="@+id/viewB"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:background="#AF3800"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageyourfriends"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#AF3800"
android:src="@drawable/your_friends" />
<ImageView
android:id="@+id/imageyourfriendrequests"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:scaleType="fitStart"
android:background="#AF3800"
android:layout_gravity="right"
android:src="@drawable/friend_requests" />
<ListView
android:id="@+id/listView5"
android:layout_marginTop="40dp"
android:layout_marginLeft="-80dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#EE6A27"
android:background="#AF3800"
android:dividerHeight="5dp"></ListView>
</RelativeLayout>有什么想法/建议,我需要改变才能得到想要的结果吗?
发布于 2015-08-17 11:44:49
<RelativeLayout
android:id="@+id/viewB"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:background="#AF3800"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageyourfriends"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
alignParentLeft="true" // add this
android:background="#AF3800"
android:src="@drawable/your_friends" />
<ImageView
android:id="@+id/imageyourfriendrequests"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:scaleType="fitStart"
android:background="#AF3800"
android:layout_gravity="right"
android:layout_toRightOf="@+id/imageyourfriends" // Add this
android:src="@drawable/friend_requests" />
<ListView
android:id="@+id/listView5"
android:layout_marginTop="40dp"
android:layout_marginLeft="-80dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#EE6A27"
android:background="#AF3800"
android:dividerHeight="5dp"></ListView>
</RelativeLayout>发布于 2015-08-17 11:41:45
对于第一个添加"alignParentLeft=true“,对于第二个添加"alignParentRight=true”。
发布于 2015-08-17 11:50:05
这样设置,添加android:layout_alignParentLeft="true**"和android:layout_alignParentRight="true"**和android:adjustViewBounds="true"。最后,更新您的ImageView部分,比如:
<ImageView
android:id="@+id/imageyourfriends"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#AF3800"
android:src="@drawable/faleavatar"
android:adjustViewBounds="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"/>
<ImageView
android:id="@+id/imageyourfriendrequests"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitStart"
android:background="#AF3800"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:src="@drawable/faleavatar" />https://stackoverflow.com/questions/32049447
复制相似问题