私は断片に線を描く必要があります。私はそれを行うには問題はないが、私は行の左と右の余白(上と下がうまくあります)がなぜわからない。ここで 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電気ショック療法のラインが大きい全幅である)
を試してみてください、あなたのルートレイアウトを表示することができますか?断片ではなく、活動。 – azizbekian
ルートレイアウトは、ビューページをレイアウト(match_parentの幅と高さ)として持つアクティビティです。それは非常に長いです。フラグメントでは、幅と高さを記録し、値は画面サイズと一致します。 – masgar