Java 填充LinearLayout中按钮之间的间隙
我有一个Java 填充LinearLayout中按钮之间的间隙,java,android,layout,Java,Android,Layout,我有一个线性布局和两个水平排列的按钮。 <LinearLayout 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="com
线性布局
和两个水平排列的按钮。<LinearLayout 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="com.example.tryingstuffs.MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="2"
/>
</LinearLayout>
</LinearLayout>
我用谷歌搜索了很多次,但我还没有找到解决问题的方法:在按钮之间——有一点空间。如何删除空格并使按钮紧跟其后?提前感谢当您在布局中使用权重时,请确保将相应的高度或宽度长度设置为零,在您的情况下为宽度,将宽度设置为零:
<LinearLayout 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="com.example.tryingstuffs.MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_blue_dark"
android:text="1"
/>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_blue_dark"
android:text="2"
/>
</LinearLayout>
</LinearLayout>
编辑
很抱歉,我已经编辑了我的答案,问题是如果你给按钮添加了背景,那么你将看不到差距,试着按照我上面编辑的方式来做
希望这有助于…使用hierarchyviewer工具查看LinearLayout中是否有空格