Я пытаюсь центрировать кнопку в середине других двух кнопок. Я пробовал использовать weight
, но не повезло (Android Studio
продолжайте говорить, что есть ошибка), используя layout_marginRight
- это не очень хорошая идея, потому что это не разрешение независимо. Вот мой код XML
Надеюсь, он поможет вам понять мою проблему.Центральная кнопка между двумя другими кнопками
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/app_bar_main"
tools:context=".MainActivity">
<TextView
android:text="Hello World!"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_bottom"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="?attr/colorPrimary"
android:layout_alignParentBottom="true"
android:minHeight="?attr/actionBarSize" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="center">
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/bottom_LeftButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lft"
android:layout_alignParentLeft="true" />
<Button
android:id="@+id/bottom_LeftCenterButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LftC"
android:layout_alignParentLeft="true" />
<Button
android:id="@+id/bottom_CenterButtom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Cnt" />
<Button
android:id="@+id/bottom_RightCenterButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RhtC"
android:layout_alignParentRight="true" />
<Button
android:id="@+id/bottom_RightButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rht"
android:layout_alignParentRight="true" />
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
Что об использовании LinearLayout с весом? – UpmostScarab
использовать 'linearLayout'. –
Вы не можете использовать весы в RelativeLAyouts. –