将按钮放在地图底部 activity
Place button in the bottom of maps activity
我在左上角有一个按钮,我需要另一个按钮,我希望它位于左下角“google”徽标所在的位置。
这就是 activity 的样子。
这是代码,我希望 buttonChatGlobal 位于左下角
<?xml version="1.0" encoding="utf-8"?>
<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=".MapsActivity" >
<Button
android:id="@+id/buttonAcercar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#359c5e"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:padding="8dp"
android:layout_margin="5dp"
android:text="Acercar/Alejar"
android:textColor="#ffffff" />
<Button
android:id="@+id/buttonChatGlobal"
android:layout_width="wrap_content"
android:gravity="bottom"
android:layout_height="wrap_content"
android:background="#359c5e"
android:padding="8dp"
android:layout_margin="5dp"
android:text="ChatGlobal"
android:textColor="#ffffff" />
</fragment>
将你的视图放在 ViewGroup
中以对齐它们你可以使用 ConstraintLayout
或 RelativeLayout
或其他 ViewGroup
我在这里使用 FrameLayout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context=".MapsActivity" >
<fragment
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"
/>
<Button
android:id="@+id/buttonAcercar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#359c5e"
android:gravity="top|start" // top left
android:padding="8dp"
android:layout_margin="5dp"
android:text="Acercar/Alejar"
android:textColor="#ffffff" />
<Button
android:id="@+id/buttonChatGlobal"
android:layout_width="wrap_content"
android:gravity="bottom"
android:layout_height="wrap_content"
android:background="#359c5e"
android:padding="8dp"
android:layout_gravity="bottom|start" // bottom left
android:layout_margin="5dp"
android:text="ChatGlobal"
android:textColor="#ffffff" />
</FrameLayout>
只需将下面的代码替换为您想要的按钮
<Button
android:id="@+id/buttonChatGlobal"
android:layout_width="wrap_content"
android:gravity="bottom"
android:layout_height="wrap_content"
android:background="#359c5e"
android:padding="8dp"
android:layout_margin="5dp"
android:text="ChatGlobal"
android:gravity="bottom|left"
android:textColor="#ffffff" />
我在左上角有一个按钮,我需要另一个按钮,我希望它位于左下角“google”徽标所在的位置。
这就是 activity 的样子。
这是代码,我希望 buttonChatGlobal 位于左下角
<?xml version="1.0" encoding="utf-8"?>
<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=".MapsActivity" >
<Button
android:id="@+id/buttonAcercar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#359c5e"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:padding="8dp"
android:layout_margin="5dp"
android:text="Acercar/Alejar"
android:textColor="#ffffff" />
<Button
android:id="@+id/buttonChatGlobal"
android:layout_width="wrap_content"
android:gravity="bottom"
android:layout_height="wrap_content"
android:background="#359c5e"
android:padding="8dp"
android:layout_margin="5dp"
android:text="ChatGlobal"
android:textColor="#ffffff" />
</fragment>
将你的视图放在 ViewGroup
中以对齐它们你可以使用 ConstraintLayout
或 RelativeLayout
或其他 ViewGroup
我在这里使用 FrameLayout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context=".MapsActivity" >
<fragment
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"
/>
<Button
android:id="@+id/buttonAcercar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#359c5e"
android:gravity="top|start" // top left
android:padding="8dp"
android:layout_margin="5dp"
android:text="Acercar/Alejar"
android:textColor="#ffffff" />
<Button
android:id="@+id/buttonChatGlobal"
android:layout_width="wrap_content"
android:gravity="bottom"
android:layout_height="wrap_content"
android:background="#359c5e"
android:padding="8dp"
android:layout_gravity="bottom|start" // bottom left
android:layout_margin="5dp"
android:text="ChatGlobal"
android:textColor="#ffffff" />
</FrameLayout>
只需将下面的代码替换为您想要的按钮
<Button
android:id="@+id/buttonChatGlobal"
android:layout_width="wrap_content"
android:gravity="bottom"
android:layout_height="wrap_content"
android:background="#359c5e"
android:padding="8dp"
android:layout_margin="5dp"
android:text="ChatGlobal"
android:gravity="bottom|left"
android:textColor="#ffffff" />