Удалите пространство между кнопками в LinearLayout (Android)
Мне нужно создать собственную панель инструментов в приложении Android.
Теперь это выглядит так: ![enter image description here]()
Итак, вы видите пробелы между кнопками. Я попытался нанести отрицательные поля/накладки на кнопки, но пространство не исчезло.
Вот код макета:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/routes_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.5">
</ListView>
<TableRow
android:id="@+id/toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:padding="0dp" >
<Button
android:id="@+id/btn_routes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:layout_weight="0.2"
android:layout_marginRight="-10dp"
android:layout_marginLeft="-10dp"
android:text="@string/routes"
android:textSize="10dp" />
<Button
android:id="@+id/btn_places"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:layout_weight="0.2"
android:layout_marginRight="-10dp"
android:layout_marginLeft="-10dp"
android:textSize="10dp"
android:text="@string/places" />
<Button
android:id="@+id/btn_events"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:layout_weight="0.2"
android:layout_marginRight="-10dp"
android:layout_marginLeft="-10dp"
android:textSize="10dp"
android:text="@string/events" />
<Button
android:id="@+id/btn_about"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:layout_weight="0.2"
android:layout_marginRight="-10dp"
android:layout_marginLeft="-10dp"
android:text="@string/about"
android:textSize="10dp" />
</TableRow>
</LinearLayout>
Как удалить пробел между кнопками?
Ответы
Ответ 1
Вот решение. Кажется, я поспешил задать здесь вопрос.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/routes_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.5">
</ListView>
<TableRow
android:id="@+id/toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom= "-7dp">
<Button
android:id="@+id/btn_routes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:layout_marginRight="-4.5dp"
android:layout_marginLeft="-5dp"
android:text="@string/routes"
android:textSize="10dp" />
<Button
android:id="@+id/btn_places"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:layout_marginRight="-4.5dp"
android:layout_marginLeft="-4.5dp"
android:textSize="10dp"
android:text="@string/places" />
<Button
android:id="@+id/btn_events"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:layout_marginRight="-4.5dp"
android:layout_marginLeft="-4.5dp"
android:textSize="10dp"
android:text="@string/events" />
<Button
android:id="@+id/btn_about"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:layout_marginRight="-4dp"
android:layout_marginLeft="-4.5dp"
android:text="@string/about"
android:textSize="10dp" />
</TableRow>
</LinearLayout>
Результат:
![enter image description here]()
Ответ 2
Попробуйте изменить цвет кнопки, потому что интерфейс по умолчанию, который является родным для android, на самом деле меньше его размера, и он установлен в центре, чтобы он выглядел круто.
Измените его на черный или что-то, и вы увидите реальный размер кнопки.
Android: фон = "# 000"
Ответ 3
попробуйте это
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/routes_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.5">
</ListView>
<TableRow
android:id="@+id/toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:padding="0dp" >
<Button
android:id="@+id/btn_routes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/routes"
android:textSize="10dp" />
<Button
android:id="@+id/btn_places"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="10dp"
android:text="@string/places" />
<Button
android:id="@+id/btn_events"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="10dp"
android:text="@string/events" />
<Button
android:id="@+id/btn_about"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/about"
android:textSize="10dp" />
</TableRow>
</LinearLayout>
Ответ 4
I won't suggest to go for -ve margins..
Скорее установите фоновое изображение для кнопки.
Некоторые важные моменты: -
- Само фоновое изображение не должно содержать пробелов на границах.
- Вам нужно создать селекторный файл для этой кнопки после предоставления фона, в котором вы будете описывать, какое изображение будет отображаться в разных состояниях кнопки, аналогично
selected
, focused
и т.д., иными словами, вы не сможете см. эффекты, которые появляются по умолчанию (например, серебряная кнопка, и когда она нажата, она становится оранжевой).
Решения: -
Мой результат: -
![enter image description here]()
Ответ 5
Просто вы можете сделать это, переопределив фоновый фон по умолчанию с закругленной формой и краем:
<Button
android:id="@+id/button_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
<!--Replace the following color with any other color or drawable-->
android:background="@android:color/white"
android:text="@string/button1_text"
android:textColor="@android:color/black" />
Ответ 6
Добавьте две строки во все кнопки и используйте Linear layout вместо tablelayout с горизонтальной ориентацией.
android:layout_width="0dp"
android:button_weight="1"