2017-04-06 11 views
0

私は断片に線を描く必要があります。私はそれを行うには問題はないが、私は行の左と右の余白(上と下がうまくあります)がなぜわからない。ここで Android canvas drawLine not full width

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     context = container.getContext(); 
     utili = new Utilities(context); 
     View rootView = inflater.inflate(R.layout.statsdepth_layout, container, false); 
     gfxView = (ImageView) rootView.findViewById(R.id.gfxview); 
     int width = context.getResources().getDisplayMetrics().widthPixels; 
     int height = context.getResources().getDisplayMetrics().heightPixels; 
     Log.i("LOGTAG", "W: " + width + " H: " + height); 
     Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 
     Canvas canvas = new Canvas(bitmap); 

     Paint paint = new Paint(); 
     paint.setColor(Color.rgb(255, 153, 51)); 
     paint.setStrokeWidth(10); 
     int startx = 0; 
     int starty = 90; 
     int endx = width; 
     int endy = 90; 
     canvas.drawLine(startx, starty, endx, endy, paint); 
     gfxView.setImageBitmap(bitmap); 

     return rootView; 
    } 

はXMLです:ここで

は私のコードです

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

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/gfxview"/> 

</LinearLayout> 

**** UPDATE ***以下のようにレイアウトを変更

、それは固定:

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

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/gfxview" 
    android:scaleType="matrix"/> 
</LinearLayout> 

結果は次のとおりです(I exp電気ショック療法のラインが大きい全幅である)

enter image description here

+1

を試してみてください、あなたのルートレイアウトを表示することができますか?断片ではなく、活動。 – azizbekian

+0

ルートレイアウトは、ビューページをレイアウト(match_parentの幅と高さ)として持つアクティビティです。それは非常に長いです。フラグメントでは、幅と高さを記録し、値は画面サイズと一致します。 – masgar

答えて

0

あなたの幅をこのように取得し、

 Display display = getWindowManager().getDefaultDisplay(); 
width = display.getWidth(); 
+0

運がよかったです。私のstartXが0なので、幅の問題はないと思うので、画面の始めに水平線が始まると思います。 (そしてgetWidth()は非推奨です) – masgar

+0

そして、ビューページャの親レイアウトのいずれかに余白がないことは確かですか? – Journey

+0

はい、私は、ビューページの最初のページがリストビューであり、幅が問題ではないと確信しています。 – masgar