我有4个imageviews通过“ 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 =“ true”,但是没有用。这就是使它们不可见或可见的方式。
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 ZQ。它将穿过不可见的位置。感谢您的帮助。
最佳答案
将其替换为方向为LinearLayout
的horizontal
:
<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);
}