Как обновить настроенный вид в макете

Я только что создал представление для отображения файла PDF

    public class PDFGraphic extends View{
     String mText;
     float mLastX;
     float mLastY;
    public float mOffX;
    public float mOffY;
    Canvas mCan;
    Bitmap mBi;

    public PDFGraphic(Context context, AttributeSet attrs){ 
        super(context,attrs);
        setPageBitmap();
        setBackgroundColor(Color.TRANSPARENT);
    }
    public void uiInvalidate() {
        postInvalidate();
    }
    public void setPageBitmap() {
        mBi = Bitmap.createBitmap(100, 100, Config.RGB_565);
        mCan = new Canvas(mBi);
        mCan.drawColor(Color.RED);
        }
   public void onDraw(Canvas canvas) {
        Paint paint = new Paint();
             canvas.drawBitmap(mBi, 0, 0, paint);
        }
}

И это мой xml-файл (pdfview):

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent" android:orientation="vertical">
    <RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="match_parent" android:gravity="bottom|center" android:layout_height="wrap_content" android:minHeight="30px" android:visibility="visible">
        <com.shawnprojectPDF.PDFGraphic android:id="@+id/pdfview1" android:layout_width="match_parent" android:layout_above="@+id/editText1" android:layout_alignParentTop="true" android:layout_height="match_parent"></com.shawnprojectPDF.PDFGraphic>
        <ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/leftarray" android:id="@+id/left" android:layout_alignParentBottom="true" android:layout_marginLeft="68px"></ImageButton>
        <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/left" android:layout_alignParentBottom="true" android:gravity="center" android:width="100px" android:singleLine="true" android:maxLength="12"></EditText>
        <ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/right" android:src="@drawable/rightarray" android:layout_toRightOf="@+id/editText1" android:layout_alignParentBottom="true"></ImageButton>
    </RelativeLayout>
</LinearLayout>

В моей основной деятельности, если setContentView (R.Layout.pdfview), представление (PDFGraphic) не будет аннулировано, если setContentView (New PDFGraphic (this)), оно будет успешно аннулировано. Как обновить вид во всем макете.


person Shawn Pan    schedule 02.08.2011    source источник


Ответы (1)


Я не вижу проблемы. Это результаты, которые я получаю с вашим кодом (в следующий раз вы сделаете эту часть). С setContentView(R.layout.pdfview) это результат:

setContentView(R.layout.pdfview)

С setContentView(new PDFGraphic(this, null) -- обратите внимание, что я использовал конструктор с двумя аргументами, потому что вы не определили PDFGraphic(Context) -- вот результат:

новый PDFGraphic()

В любом случае ваш onDraw() происходит правильно.

person cdhabecker    schedule 02.08.2011