0

I need to add an image to the screen in a table row and have text over the image.

The image is a calendar with the date displayed on top. It work fine for the first device... see image here:

enter image description here

But get too small on the larger device... see image here:

enter image description here

the code is

RelativeLayout calender_image_text = new RelativeLayout(getActivity());
        ImageView imageview1 = new ImageView(getActivity());
        imageview1.setBackgroundResource(R.mipmap.calendar);
        imageview1.setPadding(00,00,00,00);
        //imageview1.setMaxHeight(150);
        //imageview1.setMaxWidth(150);
        LinearLayout.LayoutParams imageview2param = new LinearLayout.LayoutParams(120, 80);
        imageview1param.addRule(RelativeLayout.CENTER_IN_PARENT);
        calender_image_text.addView(imageview1,imageview2param);
        //linearh1.addView(calender_image_text,tablerowparam00);

        TextView textview0 = new TextView(getActivity());
        textview0.setId(id_textview0);
        textview0.setText("Dec 0" + i);
        //textview0.setTextSize(12);
        textview0.setPadding(00,00,00,00);
        textview0.setSingleLine(false);
        textview0.setTextColor(Color.BLACK);
        //textview0.setGravity(Gravity.LEFT);
        //textview0param.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        //textview0param.addRule(RelativeLayout.LEFT_OF,imageview1.getId());
        //textview0param.addRule(RelativeLayout.RIGHT_OF,imageview1.getId());
        //textview0param.addRule(RelativeLayout.ALIGN_TOP,imageview1.getId());
        textview0param.addRule(RelativeLayout.CENTER_IN_PARENT,imageview1.getId());
        textview0.setGravity(Gravity.CENTER);
        textview0.setLayoutParams(textview0param);
        calender_image_text.addView(textview0,textview0param);
        linearh1.addView(calender_image_text,tablerowparam00);
il_raffa
  • 5,090
  • 129
  • 31
  • 36
user7236439
  • 27
  • 1
  • 6

3 Answers3

0

You should create several folders for different screens, and create different images for them. (hdpi, xhdpi, xxhdpi, xxxhdpi and other you need)

Ihor Dobrovolskyi
  • 1,241
  • 9
  • 19
0

Create different mipmap or drawable folder for different screen resolutions and place your images in it , here are drawable folder names

 drawables-ldpi  // for low density
 drawables-mdpi  //for medium density
 drawables-hdpi  //for high density
 drawables-xhdpi //for extra high density
 drawables-xxhdpi  //for extra extra high density
 drawables-xxxhdpi  //for extra extra extra high density

place your picture in all drawables with same name and android will pick images based on density of phone

your folders should be under res like this

Manohar
  • 22,116
  • 9
  • 108
  • 144
0

This layout should help you out ...

<RelativeLayout
    android:layout_width="100dp"
    android:layout_height="100dp"
    >
    <ImageView
        android:id="@+id/image_view"
        android:layout_centerInParent="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"
        android:src="@drawable/img_calendar" />

    <TextView
        android:id="@+id/text_view_date"
        android:padding="4dp"
        android:layout_centerInParent="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textColor="@color/colorBlack"
        android:gravity="center"
        android:text="Dec 4"
        android:textAlignment="center"
        android:textSize="32sp"
        />
</RelativeLayout>