0
我有一個很奇怪的問題;我希望有人知道這是什麼。我在可滾動的視圖中構建了一個表格,其中有一個2px厚的單元格邊框。在平板電腦上(三星Galaxy 10.1),它是完美的,而在星系標籤2上,它僅停止在滾動視圖的可見部分繪製邊界。我附上兩張圖片以示區別 ScrollView中的TableView中的單元格邊框
這裏是代碼 java的部分:
@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>