Je dois tracer une ligne dans un fragment. Je n'ai aucun problème à le faire mais je ne sais pas pourquoi la ligne a une marge gauche et droite (haut et bas est bien).Toile Android drawLine pas pleine largeur
Voici mon code:
@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;
}
Voici le 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>
**** MISE A JOUR ***
Changer la mise en page comme ci-dessous, il fixe:
<?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>
Et voici le résultat (I exp ect la ligne est pleine largeur grande)
Pouvez-vous montrer votre mise en page de racine? Pas le fragment, l'activité. – azizbekian
La disposition racine est une activité avec un viewpager en tant que mise en page (hauteur et hauteur match_parent). C'est très long à attacher. Dans le fragment je note la largeur et la hauteur et les valeurs correspondent à la taille de l'écran. – masgar