我有一个自定义ListActivity,其中我有一个自定义ListAdapter,它为列表中的每个项目扩展了一个布局。在eclipse中,在可视化编辑器中,布局看起来像这样
这是由以下代码完成的:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/largeFrame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="1dp"
android:layout_marginRight="3dp"
android:layout_marginTop="5dp"
android:background="@color/mainBack"
android:orientation="vertical" >
<View
android:id="@+id/imageView1"
android:layout_width="5dp"
android:layout_height="fill_parent"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="false"
android:layout_marginLeft="2dp"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/newtimeslot_class"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="4dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/black" />
<View
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_alignRight="@+id/newtimeslot_class"
android:layout_below="@+id/newtimeslot_class"
android:layout_toRightOf="@+id/imageView1"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/newtimeslot_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/newtimeslot_class"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#646464" />
<TextView
android:id="@+id/newtimeslot_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/imageView2"
android:layout_marginRight="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#646464" />
<TextView
android:id="@+id/newtimeslot_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/newtimeslot_location"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#646464" />
</RelativeLayout>
</FrameLayout>
不幸的是,当我在Android设备上运行时,左边的行完全消失了。它看起来像
我刚刚通过膨胀来完成通常,我只访问TextView对象。所以我只是想知道可能会发生什么,如果有人可以帮我摆脱这个烂摊子?
干杯
编辑:通胀代码
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final View view = mInflater.inflate(R.layout.timeslotlayout_new, parent, false);
return view;
}
答案 0 :(得分:1)
我怀疑参考 @android:color / darker_gray 是问题所在。
可能在某些设备上,此值不存在?!? (例如,它可能是另一个名称)
尝试将背景属性设置为COLOR 值(而不是Android颜色参考),例如#00000 代表黑色(或为 DarkGray 选择其他自定义颜色#A9A9A9 ):
android:background="#A9A9A9"
/ OR /
为大多数基本颜色(如完成HERE)创建XML文件,这样您就可以确保颜色不会在设备之间发生变化,最重要的是,它们将存在于应用程序的所有设备上。
因此,如果您这样做(请参阅链接),您可以创建一个这样的颜色(XML文件的名称根本不重要):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="Black">#000000</color>
<color name="DarkGray">#A9A9A9</color>
</resources>
以下列方式引用它:
android:background="@color/DarkGray"
注意: 无论这是否解决了您的问题,我强烈建议您遵循这种方式以保证安全。
答案 1 :(得分:0)
也许你错过了设置这个:
android:layout_alignParentLeft="false"
到此:
android:layout_alignParentLeft="true"
顺便说一句,android:orientation="vertical"
不适用于相对布局。它仅适用于LinearLayout
。
并newtimeslot_time
TextView
更改
android:layout_toRightOf="@+id/imageView1"
到
android:layout_toRightOf="@id/imageView1"
希望它有所帮助!
干杯!