Android 某些listview项目中的空白处
我正在编写一个带有一些自定义视图的公共列表视图。没什么特别的 但是,当我在galaxy s7中运行时,在自定义项目视图的中心创建了一个神秘的水平间距 下面是自定义项视图的抽象版本,它将在listView baseAdapter的getView()上返回Android 某些listview项目中的空白处,android,android-layout,listview,Android,Android Layout,Listview,我正在编写一个带有一些自定义视图的公共列表视图。没什么特别的 但是,当我在galaxy s7中运行时,在自定义项目视图的中心创建了一个神秘的水平间距 下面是自定义项视图的抽象版本,它将在listView baseAdapter的getView()上返回 public class CustomView extends LinearLayout { public CustomView(Context context) { super(context); LayoutInflater
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项的逻辑似乎没有什么不同。为什么会这样 我找到了解决办法。这其实不是什么特别的事。是关于九补丁聊天泡泡导致了这个问题。我找到了解决方案。这其实不是什么特别的事。这是关于导致问题的九补丁聊天泡泡。多年来,我在三星设备上看到了许多这样的问题。如果尚未设置应用程序主题,请尝试显式设置应用程序主题。三星设备默认值的实现往往有点随意。我假设您在
列表视图中只有一种视图类型。你能在布局文件中指出哪个部分属于红色和紫色吗?不,实际上,我的视图中有五种以上的视图类型。上面的代码是一个缩短版本,因为上面屏幕的结果来自该源代码。我将在示例代码中添加一个标题,以指示红色和紫色视图。多年来,我在三星设备上看到了许多这样的问题。如果尚未设置应用程序主题,请尝试显式设置应用程序主题。三星设备默认值的实现往往有点随意。我假设您在列表视图中只有一种视图类型。你能在布局文件中指出哪个部分属于红色和紫色吗?不,实际上,我的视图中有五种以上的视图类型。上面的代码是一个缩短版本,因为上面屏幕的结果来自该源代码。我将在示例代码中添加一个标题,以指示红色和紫色视图。