我需要在表格行中向屏幕添加图像,并在图像上添加文字。
图像是日历,日期显示在顶部。它适用于第一台设备......请参见此处的图片:
但是在较大的设备上太小了......请看这里的图片:
代码是
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);
答案 0 :(得分:0)
您应该为不同的屏幕创建多个文件夹,并为它们创建不同的图像。 (hdpi,xhdpi,xxhdpi,xxxhdpi和其他你需要的)
答案 1 :(得分:0)
为不同的屏幕分辨率创建不同的mipmap或drawable文件夹并将图像放入其中,这里是可绘制的文件夹名称
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
将您的照片放在所有具有相同名称的drawable中,android将根据手机的密度选择图片
你的文件夹应该在res下 like this
答案 2 :(得分:0)
这种布局可以帮助你......
<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>