我使用以下形状作为各种布局的背景,以便在我的应用程序中对数据进行逻辑分组。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#A51C4293" android:endColor="#A51C4293"
android:angle="180"/>
<corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
</shape>
一个视图是一个线性布局,它由在运行时根据XML文件的内容添加的自定义控件组成。布局定义为:
<LinearLayout
android:id="@+id/localDiningLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="16dp"
android:orientation="vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp" >
<TextView
android:id="@+id/localDiningLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="8dp"
android:gravity="center_vertical|center_horizontal"
android:paddingLeft="0dp"
android:text="Local Dining"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/plainText" />
</LinearLayout>
添加控件的代码是:
// looping through all item nodes <item>
for (int i = 0; i < nl.getLength(); i++) {
Element e = (Element)nl.item(i);
String name = this.parser.getValue(e, "Name");
String type = this.parser.getValue(e, "Type");
String street = this.parser.getValue(e, "Street");
String city = this.parser.getValue(e, "City");
String state = this.parser.getValue(e, "State");
String distance = this.parser.getValue(e, "Distance");
String website = this.parser.getValue(e, "Website");
String urbanspoon = this.parser.getValue(e, "UrbanSpoon");
String maps = this.parser.getValue(e, "Maps");
DiningElement DE = new DiningElement(C);
DE.setWebLink(website);
DE.setUSLink(urbanspoon);
DE.setNavLink(maps);
DE.SetName(name);
DE.SetType(type);
DE.SetAddress(street + ", " + city + ", " + state);
DE.SetDistance(distance);
DE.loadViews();
LL.addView(DE);
if (i < nl.getLength() - 1){
View ruler = new View(C);
ruler.setBackgroundColor(0x33FFFFFF);
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, 1);
params.setMargins(8, 0, 8, 0);
ruler.setLayoutParams(params);
LL.addView(ruler, params);
}
}
LL.setBackgroundResource(R.drawable.nonhotelgroupbubble);
LL.invalidate();
具有圆角的绘图不会在后台显示。如果我从形状中删除圆角,它看起来很好。有什么建议吗?
其他信息,这是自定义控件布局,我正在添加其中的~20个。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:orientation="vertical" >
<TextView
android:id="@+id/nameText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginTop="0dp"
android:text="Name Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/plainText" />
<TextView
android:id="@+id/typeText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginTop="0dp"
android:text="Type of food"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/plainText" />
<TextView
android:id="@+id/addressText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:text="Address"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/plainText" />
<TextView
android:id="@+id/distanceText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="Distance"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/plainText" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:gravity="center" >
<ImageButton
android:id="@+id/dining_websiteButton"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="16dp"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/web" />
<ImageButton
android:id="@+id/diningUSButton"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/urbanspoon" />
<ImageButton
android:id="@+id/diningnavButton"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="8dp"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/nav_arrow" />
</LinearLayout>
</LinearLayout>
答案 0 :(得分:0)
经过大量谷歌研究后,关闭硬件加速是唯一的解决方法。在清单中为整个应用程序设置以下内容
<application android:hardwareAccelerated="false" ...>
或活动
<activity android:hardwareAccelerated="false" />