线性布局删除元素之间的间距

时间:2017-07-30 11:31:53

标签: android android-layout android-linearlayout

我有一个带有以下布局的ListView:

<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.beric.listviewtest.MyListActivity"
    tools:showIn="@layout/activity_my_list">

    <fragment
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/feed_fragment_portrait"
        class="com.beric.listviewtest.MyListFragment"/>

</android.support.constraint.ConstraintLayout>

这会产生以下布局:

Current Layout

但我想摆脱图像左侧的空白区域,并将文本放在图像旁边:

Future Layout

我已经尝试将填充和边距设置为0dp但是没有用。

编辑:我发布的LinearLayout是ConstraintLayout的一部分:

Select customerID ........(**All **customerID** from customer Table)
Select Month      ........
select Year       ........

4 个答案:

答案 0 :(得分:0)

Remove Padding left from your listview

答案 1 :(得分:0)

you can try ..

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:weightSum="2">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="0dp"
        android:layout_weight=".5"
        android:layout_height="wrap_content">


        <ImageView
            android:layout_width="100dp"
            android:layout_height="70dp"
            android:layout_gravity="center_vertical"
            android:id="@+id/icon"
            android:src="@drawable/ic_launcher"

            />

    </LinearLayout>

    <LinearLayout

        android:layout_width="0dp"
        android:layout_weight="1.5"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"                
            android:text="title of the next to image"
            android:textStyle="bold"
            android:layout_marginTop="20dp"
            android:padding="5dp"
            android:textSize="14sp"
            />
    </LinearLayout>

</LinearLayout>

答案 2 :(得分:0)

解决方案是将android:layout_width="wrap_content"更改为android:layout_width="35dp"中的ImageView。工作代码下方:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="35dp"
        android:layout_height="35dp"
        android:layout_marginTop="1dp"
        android:layout_marginBottom="1dp"
        android:src="@drawable/ok" >
    </ImageView>

    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:text="@+id/label"
        android:textSize="20dp" >
    </TextView>

</LinearLayout>

答案 3 :(得分:0)

确保您的图片没有任何填充。如果您的图片视图有一些填充,请在图片视图中添加android:adjustViewBounds="true"

相关问题