1
我在写一个包含一些自定义视图的常见列表视图。没有什么特别的。在某些listview项目中的Android神秘保证金
但是当我在银河系s7中运行这个时,会在自定义项目视图的中心创建一个神秘的水平间距。
这是一个抽象版本的自定义项目视图,它将在listView baseAdapter的getView()上返回。
public class CustomView extends LinearLayout {
public CustomView(Context context) {
super(context);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.cell_dutch, this, true);
}
}
添加代码如setLayoutParams(新LinearLayout.LayoutParams(...,...));没有效果。
布局是如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/linearLayoutTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="3dp"
android:gravity="bottom"
android:orientation="vertical">
<TextView
android:id="@+id/textViewUnRead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginBottom="5dp"
android:text=""
android:textColor="@color/colorUnread"
android:textSize="9dp" />
<TextView
android:id="@+id/tvDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="5dp"
android:text="PM 3:11"
android:textColor="@color/color_chatcrey"
android:textSize="9dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:orientation="vertical">
<LinearLayout
android:background="@drawable/img_chat_bubble_white_you_02_android"
android:id="@+id/llBubble"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="@drawable/..."
android:id="@+id/imageView" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/..." />
<!-- RED BOX -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TOTAL"
android:textSize="10dp" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<TextView
android:id="@+id/textViewTotalPoint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="right"
android:textColor="#000000"
android:textSize="8dp"
android:textStyle="bold" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="@drawable/..." />
</LinearLayout>
</LinearLayout>
<!-- PURPLE BOX -->
<ImageButton
android:id="@+id/imageButtonSnsShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/..." />
</LinearLayout>
</LinearLayout>
在上面的截图中,红色框和紫色按钮之间应该没有间距。实际上,在android studio ui编辑器中,我没有看到任何间距,但它只是在运行时显示出来。
但在另一个项目,我做了测试,它看起来就像下面的图像很好。
似乎是在显示自定义视图作为这两个项目之间的ListView项逻辑没有区别。为什么会这样呢?
多年来,我已经看到了许多与三星设备有关的问题。尝试明确设置应用程序主题,如果你还没有。三星设备的默认设置通常有点随意。 – 323go
我假设你在'ListView'中只有一种视图类型。你能否在你的布局文件中指出哪一部分属于RED和PURPLE? – LightYearsBehind
不,实际上,我在视图中有五种以上的视图类型。上面的代码是一个缩短的版本,因为上面的屏幕的结果来自该源。我将在示例代码中添加一个标题以指示RED和紫色视图。 – March3April4