2017-07-30 50 views
0

我有以下布局一个ListView:线性布局中删除元件之间的间隔

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

    <ImageView 
     android:id="@+id/icon" 
     android:layout_width="wrap_content" 
     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> 

这将产生以下布局:

Current Layout

但我想摆脱空的空间放在图像的左侧,并将文字放在图像旁边:

Future Layout

我已经尝试设置填充和边距为0dp,但没有奏效。

编辑:我张贴的LinearLayout是ConstraintLayout的一部分:

<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> 
+0

发布你的'ListView'布局。 –

+0

添加完整的布局 –

+0

可能是您的可绘制图像有填充检查它,使用方向水平线性布局 – dharmx

回答

0

删除填充从你的列表视图左侧

0

你可以尝试..

<?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> 

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> 
+0

设置ImageView的维度不是一个好习惯......它会看起来很糟糕与设备有很大不同的规格。 – Kiya

0

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

相关问题