1

我已经尝试了很多方法来向 RemoteView 添加带有一些动态文本视图(运行时)的线性布局(xml 定义)。

我在我的 xml 布局中定义了线性布局,例如:

日历布局.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutClickable"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/myshape"
android:padding="4dp" >

<LinearLayout
    android:id="@+id/layoutParentView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_marginLeft="70dp"
    android:orientation="vertical"
    android:padding="4dp" >

</LinearLayout>

并尝试在我的远程视图中使用它和一些动态文本视图。

RemoteViews remoteViews = new RemoteViews(context
            .getApplicationContext().getPackageName(), R.layout.calendarlayout);
for(int i=0; i<event_row_counter; i++ ){
CalendarEvent mCalendarEvent = new CalendarEvent();
mCalendarEvent = CALENDAR_EVENTS.get(i);    
TextView mTextView = new TextView(context);
mTextView.setId(i);

RemoteViews textRemoteView = new 
RemoteViews(context.getApplicationContext().getPackageName(), R.layout.calendarlayout);
remoteViews.setTextViewText(mTextView.getId(), mCalendarEvent.getFormatedTime()+" "+mCalendarEvent.getTitle());
remoteViews.addView(R.layout.calendarlayout, textRemoteView);          
}

我知道我的过程完全错误,但我无法找到任何方法将带有动态文本视图的线性布局添加到远程视图中。

建议大多赞赏。

4

0 回答 0