【发布时间】:2016-07-13 07:19:39
【问题描述】:
我正在处理一个小部件,但在将视图添加到我的 RemoteView 时遇到了问题。
仅显示添加的第一个项目(视图)。
PS : 我需要横向添加视图。
这是我在RemoteViews 中添加视图的循环:
RemoteViews mainView = new RemoteViews(getPackageName(), R.layout.widget);
mainView.removeAllViews(R.id.view_container);
for (int i = 0; i < Constant.max; i++) {
RemoteViews newView = new RemoteViews(getPackageName(), R.layout.item);
newView.setImageViewBitmap(R.id.logo, Constant.data[i].getLogo());
mainView.addView(R.id.view_container, newView);
Log.e("Item added : ", Constant.data[i].getName());
}
widget.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
<LinearLayout
android:orientation="horizontal"
android:id="@+id/view_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout>
</RelativeLayout>
item.xml
<?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="fill_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_between"
android:layout_marginRight="@dimen/margin_between"
android:background="#F0F0F0"
android:orientation="vertical"
android:padding="2dp">
<ImageView
android:id="@+id/logo"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:src="@drawable/ic_android_black_24dp" />
</LinearLayout>
</LinearLayout>
如果您有任何解决此问题的想法.. 提前致谢。
【问题讨论】:
标签: java android xml android-widget remoteview