将ImageView移动到布局右侧

时间:2017-11-22 19:57:18

标签: java android xml maps

我有4个图像视图相互连接" toLeftOf"命令。问题是当我把其中一个隐形时,另一个停留在同一个位置或者走到布局的左侧。

<FrameLayout 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"
    tools:context=".MapsActivity" >

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.ahmetbesli.eczanem.MapsActivity" />
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/relative"
        android:layout_gravity="bottom"
        android:layout_marginBottom="85dp">
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/direction"
            android:src="@drawable/ic_directions_black_24dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:visibility="visible"
            android:background="@drawable/rounded_corner"
            android:animateLayoutChanges="true"/>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/bullet"
            android:src="@drawable/ic_format_align_left_black_24dp"
            android:layout_toLeftOf="@+id/direction"
            android:layout_toStartOf="@+id/direction"
            android:visibility="visible"
            android:background="@drawable/rounded_corner"
            android:layout_marginRight="1dp"
            android:layout_marginEnd="1dp"
            android:animateLayoutChanges="true"/>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/share"
            android:src="@drawable/ic_share_black_24dp"
            android:layout_toLeftOf="@+id/bullet"
            android:layout_toStartOf="@+id/bullet"
            android:visibility="visible"
            android:background="@drawable/rounded_corner"
            android:layout_marginRight="1dp"
            android:layout_marginEnd="1dp"
            android:animateLayoutChanges="true"/>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/access"
            android:src="@drawable/ic_accessibility_black_24dp"
            android:layout_toLeftOf="@+id/share"
            android:layout_toStartOf="@+id/share"
            android:visibility="visible"
            android:background="@drawable/rounded_corner"
            android:layout_marginRight="1dp"
            android:layout_marginEnd="1dp"
            android:animateLayoutChanges="true"/>
    </RelativeLayout>
</FrameLayout>

我使用了animateLayoutChanges =&#34; true&#34;但它不起作用。这就是让它们看不见或可见的方式。

if (!marker.getTitle().equals("Buradasın")) {
                    latLngMaps = marker.getPosition();
                    share.setVisibility(View.VISIBLE);
                    direction.setVisibility(View.VISIBLE);
                    bullet.setVisibility(View.VISIBLE);
                    access.setVisibility(View.VISIBLE);
                } else {
                    bullet.setVisibility(View.VISIBLE);
                    share.setVisibility(View.INVISIBLE);
                    direction.setVisibility(View.INVISIBLE);
                    access.setVisibility(View.INVISIBLE);
                }

想要做的就是让他们像X Y Z Q一样 当我让Y看不见它必须像X Z Q.它将穿过看不见的地方。谢谢你的帮助。

2 个答案:

答案 0 :(得分:1)

如果您希望视图在隐藏时不填充空格,则应使用GONE代替INVISIBLE

 access.setVisibility(View.GONE);

https://developer.android.com/reference/android/transition/Visibility.html \

<强>更新

替换imageview布局的容器,替换为:

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/relative"
        android:layout_gravity="bottom"
        android:layout_marginBottom="85dp">

由此:

 <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/relative"
        android:layout_gravity="bottom"
        android:layout_marginBottom="85dp">

答案 1 :(得分:1)

将其替换为方向为horizontal的{​​{1}}:

<LinearLayout
    android:id="@+id/relative"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:layout_marginBottom="85dp"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/direction"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/rounded_corner"
        android:src="@drawable/ic_directions_black_24dp"/>

    <ImageView
        android:id="@+id/bullet"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="1dp"
        android:layout_marginRight="1dp"
        android:background="@drawable/rounded_corner"
        android:src="@drawable/ic_format_align_left_black_24dp"/>

    <ImageView
        android:id="@+id/share"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="1dp"
        android:layout_marginRight="1dp"
        android:background="@drawable/rounded_corner"
        android:src="@drawable/ic_share_black_24dp" />

    <ImageView
        android:id="@+id/access"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="1dp"
        android:layout_marginRight="1dp"
        android:background="@drawable/rounded_corner"
        android:src="@drawable/ic_accessibility_black_24dp" />
</LinearLayout>

并将可见性设置为GONE而不是INVISIBLE

            if (!marker.getTitle().equals("Buradasın")) {
                latLngMaps = marker.getPosition();
                share.setVisibility(View.VISIBLE);
                direction.setVisibility(View.VISIBLE);
                bullet.setVisibility(View.VISIBLE);
                access.setVisibility(View.VISIBLE);
            } else {
                bullet.setVisibility(View.VISIBLE);
                share.setVisibility(View.GONE);
                direction.setVisibility(View.GONE);
                access.setVisibility(View.GONE);
            }
相关问题