2013-04-22 4 views
0

매우 이상한 문제가 있습니다. 누군가이게 뭔지 알기를 바랍니다. 2px 두께의 셀 경계를 사용하여 스크롤 가능한보기로 표를 작성합니다. 태블릿 (삼성 갤럭시 10.1)에서는 완벽합니다. 갤럭시 탭 2에서는 스크롤보기의 보이는 부분에만 테두리를 그립니다.ScrollView 내에서 TableView의 셀 테두리

@Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup container, 
       Bundle savedInstanceState) { 
      super.onCreateView(inflater, container, savedInstanceState); 
      scrollView1=(HorizontalScrollView) firstView.findViewById(R.id.horizontalScrollView1); 
      //position the scroller to the present time 
      scrollView1.post(new Runnable() { 
       public void run() { 
        if((Calendar.getInstance().get(Calendar.HOUR_OF_DAY)>3)) 
        scrollView1.scrollTo(CELL_WIDTH*((Calendar.getInstance().get(Calendar.HOUR_OF_DAY))-3), 0); 
       } 
     }); 

      headerPaint = new Paint(); 
      headerPaint.setStyle(Paint.Style.STROKE); 
      headerPaint.setColor(Color.GRAY); 
      headerPaint.setStrokeWidth(2); 

      cellPaint = new Paint(); 
      cellPaint.setStyle(Paint.Style.STROKE); 
      cellPaint.setColor(Color.GRAY); 
      cellPaint.setStrokeWidth(2); 

      textViewData.setText(formatter.format(dateToShow.getTime())); 
      imageButtonDateAfter.setOnClickListener(new View.OnClickListener() { 
       public void onClick(View v) { 
        Calendar oggi = Calendar.getInstance(); 
        oggi.set(Calendar.HOUR_OF_DAY, 23); 
        oggi.set(Calendar.MINUTE, 59); 
        dateToShow.add(Calendar.DAY_OF_MONTH, 1); 
       } 
      }); 
      loadElementiInTable(); 
      return firstView; 
     } 

//for space reasons i show you only the first row code (the hours of the day) 
private void loadElementiInTable() { 
     tableLayoutElementi.removeAllViews(); 
     tableLayoutHeader.removeAllViews(); 
     ArrayList<Integer> orari = new ArrayList<Integer>(); 
     orari = loadListOrari(); 
     listPasti = new ArrayList<Pasto>(); 
     listGlicemie = new ArrayList<Glicemia>(); 
     listBoli = new ArrayList<Administration>(); 
     TableRow hoursRow=new TableRow(getActivity().getApplicationContext()); 
     TableRow hoursHeaderRow=new TableRow(getActivity().getApplicationContext()); 
     TableRow hoursSepRow = new TableRow(getActivity().getApplicationContext()); 
     TextView legendanew=new TextView(getActivity().getApplicationContext()); 

     legendanew.setText("Campo"); 
     legendanew.setWidth(HEADER_WIDTH); 
     legendanew.setGravity(Gravity.CENTER); 
     hoursHeaderRow.addView(legendanew); 

     for (final Integer j : orari) { 
     TextView ora1=new TextView(getActivity().getApplicationContext()){ 
      @Override 
      protected void onDraw(Canvas canvas) { 
       super.onDraw(canvas); 
       Rect rect = new Rect(); 
       Paint paint = new Paint(); 
       paint.setStyle(Paint.Style.STROKE); 
       paint.setColor(Color.GRAY); 
       paint.setStrokeWidth(2); 
       getLocalVisibleRect(rect); 
       canvas.drawRect(rect, paint);  
      } 

     }; 
     ora1.setTextColor(Color.DKGRAY); 
     ora1.setGravity(Gravity.CENTER); 
     TextView sepOra=new TextView(getActivity().getApplicationContext()); 
     ora1.setText(j+":00"); 
     if(j==Calendar.getInstance().get(Calendar.HOUR_OF_DAY)){ 
      ora1.setBackgroundColor(Color.YELLOW); 
     } 
     ora1.setWidth(CELL_WIDTH); 
     hoursRow.addView(ora1); 
     //hoursRow.addView(sepOra); 
     } 

     TableRow glicemiaRow = new TableRow(getActivity().getApplicationContext()); 
     TableRow glicemiaHeaderRow = new TableRow(getActivity().getApplicationContext()); 
     TextView glicemiaLabel=new TextView(getActivity().getApplicationContext()){ 
      @Override 
      protected void onDraw(Canvas canvas) { 
       super.onDraw(canvas); 
       Rect rect = new Rect(); 
       getLocalVisibleRect(rect); 
       canvas.drawRect(rect, headerPaint);  
      } 

     }; 
     glicemiaLabel.setText("Glicemia"); 
     formatAsHeader(glicemiaLabel); 
     glicemiaHeaderRow.addView(glicemiaLabel); 
     TextView glicemiaTuttoIlGiorno=new TextView(getActivity().getApplicationContext()){ 
      @Override 
      protected void onDraw(Canvas canvas) { 
       super.onDraw(canvas); 
       Rect rect = new Rect(); 
       getLocalVisibleRect(rect); 
       canvas.drawRect(rect, cellPaint);  
      } 
     }; 
     if(showTuttoIlGiorno){ 
     glicemiaTuttoIlGiorno.setText(EMPTY_CELL); 
     formatAsTuttoIlGiorno(glicemiaTuttoIlGiorno); 
     glicemiaHeaderRow.addView(glicemiaTuttoIlGiorno); 
     } 

     tableLayoutElementi.setStretchAllColumns(true); 
     legendanew.setWidth(100); 
     noteRow.setBaselineAligned(false); 
     noteHeaderRow.setBaselineAligned(false); 
     tableLayoutElementi.addView(noteRow, 0, new TableLayout.LayoutParams(100, CELL_HEIGHT)); 
     tableLayoutHeader.addView(noteHeaderRow, 0, new TableLayout.LayoutParams(100, CELL_HEIGHT)); 
     boloRow.setBaselineAligned(false); 
     boloHeaderRow.setBaselineAligned(false); 
     tableLayoutElementi.addView(boloRow, 0, new TableLayout.LayoutParams(100, CELL_HEIGHT)); 
     tableLayoutHeader.addView(boloHeaderRow, 0, new TableLayout.LayoutParams(100, CELL_HEIGHT)); 
     pastoRow.setBaselineAligned(false); 
     pastoHeaderRow.setBaselineAligned(false); 
     tableLayoutElementi.addView(pastoRow, 0, new TableLayout.LayoutParams(100, CELL_HEIGHT)); 
     tableLayoutHeader.addView(pastoHeaderRow, 0, new TableLayout.LayoutParams(100, CELL_HEIGHT)); 
     glicemiaRow.setBaselineAligned(false); 
     glicemiaHeaderRow.setBaselineAligned(false); 
     tableLayoutElementi.addView(glicemiaRow, 0, new TableLayout.LayoutParams(100, CELL_HEIGHT)); 
     tableLayoutHeader.addView(glicemiaHeaderRow, 0, new TableLayout.LayoutParams(100, CELL_HEIGHT)); 
     tableLayoutHeader.addView(hoursHeaderRow, 0, new TableLayout.LayoutParams(100, heightColonna)); 
     tableLayoutElementi.addView(hoursRow, 0, new TableLayout.LayoutParams(100, heightColonna)); 
    } 
    } 

xml 파일 (테이블 만 부분) :

<RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="10" > 

     <HorizontalScrollView 
      android:id="@+id/horizontalScrollView1" 
      android:layout_width="1080dp" 
      android:layout_height="match_parent" 
      android:layout_alignParentRight="true" > 

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

      <TableLayout 
       android:id="@+id/tableLayoutElementi" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="@color/white" > 
      </TableLayout> 

</LinearLayout> 

      </HorizontalScrollView> 

     <LinearLayout 
      android:id="@+id/headerleft" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

      <TableLayout 
       android:id="@+id/tableLayoutHeader" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" > 

       <TableRow 
        android:id="@+id/tableRow1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" > 

        <TextView 
         android:id="@+id/textView1" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="TextView" /> 

       </TableRow> 

       <TableRow 
        android:id="@+id/tableRow2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" > 

        <TextView 
         android:id="@+id/textView2" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="TextView" /> 

       </TableRow> 

       <TableRow 
        android:id="@+id/tableRow3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" > 
        <TextView 
         android:id="@+id/textView3" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="TextView" /> 
       </TableRow> 
       <TableRow 
        android:id="@+id/tableRow4" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" > 
       </TableRow> 
      </TableLayout> 
     </LinearLayout> 
    </RelativeLayout> 
나는 Samsung Galaxy tab 10.1

다음

Samsung galaxy tab 2 (scrolling a little to the right)

코드 자바 부분의 차이를 보여주기 위해이 사진을 첨부

답변

0

왜 이런 일이 발생하는지 이해하지 못했지만이 텍스트 뷰 선언을 제거하여 해결했습니다. NS :

TextView cell = new TextView(getActivity().getApplicationContext()) { 
       @Override 
       protected void onDraw(Canvas canvas) { 
        super.onDraw(canvas); 
        Rect rect = new Rect(); 
        getLocalVisibleRect(rect); 
        canvas.drawRect(rect, cellPaint);  
       } 
      }; 

대신이 퍼팅 :

borded_cell가 당김 내가 입술에 넣어 xml 파일 /입니다
TextView cell = new TextView(getActivity().getApplicationContext()); 
v.setBackgroundDrawable(getResources().getDrawable(R.drawable.borded_cell)); 

:

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > 
    <solid android:color="#ffffff" /> 
    <stroke android:width="1dip" android:color="#4fa5d5"/> 
</shape> 
관련 문제