2013-02-07 25 views
6

Tôi đang cố gắng tạo tiện ích con cho ứng dụng, sau đây là bố cục tôi đang sử dụng. Tôi đã cố thêm chế độ xem cuộn vào phần thứ hai của tiện ích. Tôi không thể làm điều đó, Khi tôi xóa thẻ, tiện ích con đang được hiển thị, nhưng khi có thẻ, android không thể tải tiện ích. Tôi gãi đầu với điều này trong hai ngày. Tôi không hiểu tôi đang làm gì sai?Không thể thêm <ScrollView> vào bố cục tiện ích con ứng dụng android

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/background_light" 
    > 

     <RelativeLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="@android:color/background_dark" 
      android:id="@+id/widgetHeader" 
      > 

      <Button 
       android:background="@drawable/icon_quickword" 
       android:id="@+id/widgetBtn" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_vertical" 
       android:layout_margin="5sp" 
      /> 

      <TextView android:text="@string/widget_title1" 
       android:id="@+id/widget_title1" 
       android:textSize="18sp" 
       android:textStyle="bold" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_vertical" 
       android:textColor="@android:color/white" 
       android:layout_toRightOf="@id/widgetBtn" 
       android:layout_marginLeft="2sp" 
       /> 

      <TextView android:text="@string/widget_title2" 
       android:id="@+id/widget_title2" 
       android:textSize="15sp" 
       android:textStyle="italic" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_vertical" 
       android:textColor="@android:color/white" 
       android:layout_toRightOf="@id/widgetBtn" 
       android:layout_below="@id/widget_title1" 
       android:layout_marginLeft="3sp" 
       /> 


     </RelativeLayout> 

      <ScrollView 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      > 

      <LinearLayout 
       android:id="@+id/widgetContent" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:background="@android:color/white" 
       > 

       <TextView android:text="@string/widget_content_info1" 
        android:id="@+id/widget_content_info1" 
        android:textStyle="bold" 
        android:textSize="16sp" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_vertical" 
        android:textColor="@android:color/black" /> 

       <TextView android:text="@string/widget_content_info2" 
        android:id="@+id/widget_content_info2" 
        android:textSize="14sp" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_vertical" 
        android:textColor="@android:color/black" /> 

       <TextView android:text="@string/widget_content_info3" 
        android:id="@+id/widget_content_info3" 
        android:textSize="14sp" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_vertical" 
        android:textColor="@android:color/black" /> 

      </LinearLayout> 
     </ScrollView> 

</LinearLayout>                    
+1

Sử dụng một ListView thay –

Trả lời

2
 <ScrollView 
      android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
     > 

    <LinearLayout 
     android:id="@+id/widgetContent" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:background="@android:color/white" 
     > 

     <TextView android:text="@string/widget_content_info1" 
      android:id="@+id/widget_content_info1" 
      android:textStyle="bold" 
      android:textSize="16sp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:textColor="@android:color/black" /> 

     <TextView android:text="@string/widget_content_info2" 
      android:id="@+id/widget_content_info2" 
      android:textSize="14sp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:textColor="@android:color/black" /> 

     <TextView android:text="@string/widget_content_info3" 
      android:id="@+id/widget_content_info3" 
      android:textSize="14sp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:textColor="@android:color/black" /> 

    </LinearLayout> 

    **</ScrollView>** 
+0

ur không kết thúc cuộn vie w tag – duggu

+0

Tôi không nên sử dụng thẻ, nhưng tại sao? Điều gì sẽ xảy ra nếu tôi chỉ muốn cung cấp chế độ xem có thể cuộn ở giữa màn hình, hãy giữ các bộ phận ở trên và dưới cố định? – Amol

0

Sau khi sử dụng tất cả các thuộc tính đóng cái nhìn của bạn với thẻ kết thúc. đóng số ScrollView của bạn với thẻ kết thúc.

<ScrollView android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout 
     android:id="@+id/widgetContent" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:background="@android:color/white" 
     > 
    </LinearLayout> 

</ScrollView> 
+0

Tôi đã thêm, vẫn có điều gì đó không đúng, đã cập nhật câu hỏi với bố cục mới. – Amol

+0

Thêm một số văn bản khác dùng thử. bởi vì chiều dài của nó ngắn. – MuraliGanesan

4

Tôi nghĩ scrollview không được hỗ trợ trong Android App-Widget (tiện ích trong màn hình chính, nếu đó là ý của bạn!). Danh sách các quan điểm được hỗ trợ là here

+0

Ngang cuộn (HorizontalScrollView) không được hỗ trợ. ScrollView, tôi tin là được hỗ trợ. –

+1

Tôi đã thử với chế độ xem cuộn trong appwidget, nhưng tiện ích thậm chí không tải. Và tài liệu chính thức không liệt kê Chế độ xem cuộn được hỗ trợ –

1

Scroll chỉ xem có thể lưu trữ một đứa trẻ, tốt hơn sử dụng một ListView

1

bạn có thể sử dụng ListView với chỉ 1 mục danh sách (bố trí của bạn)

get mẫu cho xem danh sách here

và sửa đổi ListProvider.java

public int getCount() { 
return 1; 
} 
public RemoteViews getViewAt(int position) { 
    RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.your_origin_layout); 
    remoteView.setTextViewText(R.id.content, "your Text"); 
    // add other pocess here 
    return remoteView; 
} 
Các vấn đề liên quan