Java Android在可扩展列表视图中设置视图背景时出现问题
我试图用可展开列表的父视图设置一个特定视图的颜色,但是当我这样做时,我发现子视图中的颜色也受到影响,这很奇怪 将视图从白色改为黑色似乎解决了这个问题,这似乎只出现在一些手机上,这真的开始让我发疯,但我找不到任何人遇到同样的问题 下面是扩展BaseExpandableListAdapter的自定义类Java Android在可扩展列表视图中设置视图背景时出现问题,java,android,colors,background,expandablelistview,Java,Android,Colors,Background,Expandablelistview,我试图用可展开列表的父视图设置一个特定视图的颜色,但是当我这样做时,我发现子视图中的颜色也受到影响,这很奇怪 将视图从白色改为黑色似乎解决了这个问题,这似乎只出现在一些手机上,这真的开始让我发疯,但我找不到任何人遇到同样的问题 下面是扩展BaseExpandableListAdapter的自定义类 public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGr
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(SUM_HOST, parent, false);
}
View statView = (View)v.findViewById(R.id.statViewABCDE);
int caseTest = hostParents.get(groupPosition).getState();
switch (caseTest) {
case Constants.STATE_OK:
statView.setBackgroundColor(ctx.getResources().getColor(R.color.host_up_state));
break;
case Constants.STATE_DOWN:
statView.setBackgroundColor(ctx.getResources().getColor(R.color.host_down_state));
break;
case Constants.STATE_UNKNOWN:
statView.setBackgroundColor(ctx.getResources().getColor(R.color.host_unreachable_state));
break;
}
return v;
}
以下是我的父级XML文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="0dp" >
<LinearLayout
android:id="@+id/sumHostLay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/defViewMargin"
android:layout_marginRight="@dimen/defViewMargin"
android:layout_marginTop="@dimen/defViewMargin"
android:background="@drawable/rounded_corners_background"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="@dimen/defViewPadding" >
<View
android:id="@+id/statViewABCDE"
android:layout_width="3dip"
android:layout_height="fill_parent"
android:background="@android:color/black" />
<TextView
android:id="@+id/sumHostTitleAndOutput"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:singleLine="true"
android:text="@string/hostrow_hostname"
android:textSize="13sp" />
</LinearLayout>
这是我给孩子的XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="0dp" >
<LinearLayout
android:id="@+id/asdasd"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="@dimen/defViewMargin"
android:orientation="vertical" >
<View
android:id="@+id/line1"
android:layout_width="1dip"
android:layout_height="fill_parent"
android:layout_margin="3dp"
android:background="@android:color/white" />
</LinearLayout>
<LinearLayout
android:id="@+id/line2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" >
<View
android:id="@+id/line4"
android:layout_width="20dp"
android:layout_height="1dp"
android:background="@android:color/white" />
</LinearLayout>
理论上,我只是试图在父XML中设置视图,即statViewABCDE,但是我发现子视图中的背景颜色也在变化。具体而言,“line1”和“line4”正在更改
编辑:
将线条设置为不同的颜色(即一组为黑色,另一组为白色)似乎已经奏效,但我不知道为什么
在运行安卓4.1.2的手机上进行测试时发现了这个问题。我找不到任何确凿的证据证明这里发生了什么 为了解决这个问题,我在java中设置了每个视图的背景颜色,这似乎解决了这个问题