andorid_关于TextView后面ImageView挤没的问题解决

 希望同时实现的样式一:当TextView内的文字不超过屏幕宽度 ImageView跟在TextView后面



希望同时实现的样式二:当TextView内的文字超过屏幕宽度 ImageView要显示出来,TextView中的文字结尾省略



直接上布局

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

	<LinearLayout
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:orientation="horizontal">
		<TextView
			android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:layout_weight="1"
			android:singleLine="true"
			android:textSize="14.0dip"
			android:gravity="center_vertical"
			android:text="123123123"
			android:layout_marginRight="5dip"
			android:textColor="@color/font_black"/>
		<ImageView
			android:layout_width="15dip"
			android:layout_height="15dip"
			android:src="@color/bg_blue2"/>
	</LinearLayout>
</RelativeLayout>

关键点在于TextView的weight属性以及width属性的设置。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
在 Android 中,ImageView 的最大像素大小可以通过设置 ImageView 的 maxWidth 和 maxHeight 属性来限制。这些属性指定了 ImageView 可以显示的最大宽度和高度,当 ImageView 中的图片超过这个值时,Android 系统会自动缩放图片以适应这个大小。 另外,如果你想要限制 ImageView 中图片的实际像素大小,可以在加载图片时使用 BitmapFactory 来读取图片的原始信息,并根据需要缩放图片。例如,下面的代码可以读取一个图片文件的原始信息,并将图片缩放到指定的最大像素大小: ```java BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(filePath, options); int imageHeight = options.outHeight; int imageWidth = options.outWidth; int maxSize = 1024; // 指定最大像素大小 if (imageHeight > maxSize || imageWidth > maxSize) { float ratio = Math.max((float) imageWidth / maxSize, (float) imageHeight / maxSize); options.inSampleSize = Math.round(ratio); } options.inJustDecodeBounds = false; Bitmap bitmap = BitmapFactory.decodeFile(filePath, options); imageView.setImageBitmap(bitmap); ``` 在这个例子中,我们首先使用 options.inJustDecodeBounds = true 来告诉 BitmapFactory 只读取图片的原始信息,不加载整个图片。然后,我们可以从 options.outHeight 和 options.outWidth 属性获取图片的原始大小。接下来,我们根据指定的最大像素大小 maxSize,计算出需要缩放的比例 ratio,并将其设置为 options.inSampleSize 属性,最后使用 BitmapFactory.decodeFile 方法读取缩放后的图片。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值