首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓-对齐2 imageViews

安卓-对齐2 imageViews
EN

Stack Overflow用户
提问于 2015-08-17 11:39:56
回答 5查看 43关注 0票数 1

我有一个问题,使两个图像视图在同一条线上。我希望其中一个图像视图(imageyourfriends)在左边对齐,而另一个(imageyourfriendrequests)在右边。我一直在尝试不同的方法,但没有一种可行。到目前为止,我有这段代码(但我的一个图像视图在另一个下方)

代码语言:javascript
复制
    <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>

有什么想法/建议,我需要改变才能得到想要的结果吗?

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2015-08-17 11:44:49

代码语言:javascript
复制
<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>
票数 1
EN

Stack Overflow用户

发布于 2015-08-17 11:41:45

对于第一个添加"alignParentLeft=true“,对于第二个添加"alignParentRight=true”。

票数 2
EN

Stack Overflow用户

发布于 2015-08-17 11:50:05

这样设置,添加android:layout_alignParentLeft="true**"android:layout_alignParentRight="true"**和android:adjustViewBounds="true"。最后,更新您的ImageView部分,比如:

代码语言:javascript
复制
<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" />
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32049447

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档