Android 如何使listview中的按钮适合任何屏幕

Android 如何使listview中的按钮适合任何屏幕,android,xml,listview,button,Android,Xml,Listview,Button,我正在编写一个xml代码,但我有两个问题,a。使按钮适合屏幕b.移除按钮之间的空间。如何使列表视图中的按钮适合任何屏幕,以及如何删除按钮之间的空格。请在回答时编辑我的代码,谢谢 我认为默认android按钮之间的间隙或边距来自按钮中使用的背景图像 第一选项 您可以像这样使用android按钮样式 <Button android:id="@+id/button01" android:layout_width="match_parent" a

我正在编写一个xml代码,但我有两个问题,a。使按钮适合屏幕b.移除按钮之间的空间。如何使列表视图中的按钮适合任何屏幕,以及如何删除按钮之间的空格。请在回答时编辑我的代码,谢谢



我认为默认android按钮之间的间隙或边距来自按钮中使用的背景图像

第一选项 您可以像这样使用android按钮样式

<Button
        android:id="@+id/button01"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        style="?android:attr/buttonBarButtonStyle"
        android:background="@color/colorPrimary"
        android:layout_weight="1"/>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button01"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorPrimary"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/Button02"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorPrimary"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/button03"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorPrimary"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/button04"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorPrimary"
        android:layout_weight="1" />

</LinearLayout>

第二种选择是在每个按钮上使用背景色。所以完整的代码是这样的

<Button
        android:id="@+id/button01"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        style="?android:attr/buttonBarButtonStyle"
        android:background="@color/colorPrimary"
        android:layout_weight="1"/>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button01"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorPrimary"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/Button02"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorPrimary"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/button03"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorPrimary"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/button04"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorPrimary"
        android:layout_weight="1" />

</LinearLayout>

前后图像


我认为默认android按钮之间的间隙或边距来自按钮中使用的背景图像

第一选项 您可以像这样使用android按钮样式

<Button
        android:id="@+id/button01"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        style="?android:attr/buttonBarButtonStyle"
        android:background="@color/colorPrimary"
        android:layout_weight="1"/>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button01"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorPrimary"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/Button02"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorPrimary"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/button03"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorPrimary"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/button04"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorPrimary"
        android:layout_weight="1" />

</LinearLayout>

第二种选择是在每个按钮上使用背景色。所以完整的代码是这样的

<Button
        android:id="@+id/button01"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        style="?android:attr/buttonBarButtonStyle"
        android:background="@color/colorPrimary"
        android:layout_weight="1"/>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button01"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorPrimary"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/Button02"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorPrimary"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/button03"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorPrimary"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/button04"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorPrimary"
        android:layout_weight="1" />

</LinearLayout>

前后图像


我不能在不使用背景色技巧的情况下关闭空间,因为我认为它来自默认的背景图像。可能是透明图像边框,默认背景图像,我不使用任何,如果有默认,它从哪里来,如何删除itI我不确定,但你可以检查android source codecant中的Button view类我关闭空间而不使用背景色技巧,因为我认为它来自默认的背景图像。可能是透明图像边框,默认背景图像,我不使用任何,如果有默认,它从哪里来,如何删除itI我不确定,但你可以检查android源代码中的按钮视图类