我有一个GridView.数据GridView是来自服务器的请求.
这是项目布局GridView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/analysis_micon_bg"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/half_activity_vertical_margin"
android:paddingLeft="@dimen/half_activity_horizontal_margin"
android:paddingRight="@dimen/half_activity_horizontal_margin"
android:paddingTop="@dimen/half_activity_vertical_margin" >
<ImageView
android:id="@+id/ranking_prod_pic"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/app_name"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/ranking_rank_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/ranking_prod_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/ranking_prod_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我从服务器请求数据,获取图像URL并加载图像 Bitmap
public static Bitmap loadBitmapFromInputStream(InputStream is) {
return BitmapFactory.decodeStream(is);
}
public static Bitmap loadBitmapFromHttpUrl(String url) {
try {
return loadBitmapFromInputStream((InputStream) (new URL(url).getContent()));
} catch (Exception e) {
Log.e(TAG, e.getMessage());
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
并且getView(int …
我想ImageView用边距为我的布局添加未知数量的视图.在XML中,我可以layout_margin像这样使用:
<ImageView android:layout_margin="5dip" android:src="@drawable/image" />
有ImageView.setPadding(),但没有ImageView.setMargin().我认为这是顺利的ImageView.setLayoutParams(LayoutParams),但不确定该提供什么.
有人知道吗?
我有一个表示BitMap图像的Base64字符串.
我需要再次将该String转换为BitMap图像,以便在我的Android应用程序中的ImageView上使用它
怎么做?
这是我用来将图像转换为base64字符串的代码:
//proceso de transformar la imagen BitMap en un String:
//android:src="c:\logo.png"
Resources r = this.getResources();
Bitmap bm = BitmapFactory.decodeResource(r, R.drawable.logo);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
//String encodedImage = Base64.encode(b, Base64.DEFAULT);
encodedImage = Base64.encodeBytes(b);
Run Code Online (Sandbox Code Playgroud) 我有一个垂直的LinearLayout,其中一个项目是ImageView使用Picasso加载的.我需要将图像的宽度提升到整个设备宽度,并显示图像的中心部分被固定高度(150dp)裁剪.我目前有以下代码:
Picasso.with(getActivity())
.load(imageUrl)
.placeholder(R.drawable.placeholder)
.error(R.drawable.error)
.resize(screenWidth, imageHeight)
.centerInside()
.into(imageView);
Run Code Online (Sandbox Code Playgroud)
我应该把哪个值成screenWidth和imageHeight(= 150dp)?
如何将随机大小的图像拟合到ImageView?
什么时候:
ImageView尺寸为250dp*250dpImageView缩放后,尺寸应与缩放图像的尺寸相匹配例如,对于100*150的图像,图像ImageView应为166*250.
例如,对于150*100的图像,图像ImageView应为250*166.
如果我将界限设置为
<ImageView
android:id="@+id/picture"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:adjustViewBounds="true" />
Run Code Online (Sandbox Code Playgroud)
图像适合在ImageView,但ImageView总是250dp*250dp.
我使用以下代码在ImageView中旋转图像一个角度.有没有更简单,更简单的方法可用.
ImageView iv = (ImageView)findViewById(imageviewid);
TextView tv = (TextView)findViewById(txtViewsid);
Matrix mat = new Matrix();
Bitmap bMap = BitmapFactory.decodeResource(getResources(),imageid);
mat.postRotate(Integer.parseInt(degree));===>angle to be rotated
Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0,bMap.getWidth(),bMap.getHeight(), mat, true);
iv.setImageBitmap(bMapRotate);
Run Code Online (Sandbox Code Playgroud) 我需要在所有活动/视图中包含标题图形.带标题的文件名为header.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#0000FF"
android:padding="0dip">
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="0dip"
android:layout_marginTop="0dip"
android:layout_marginBottom="0dip"
android:padding="0dip"
android:paddingTop="0dip"
android:paddingBottom="0dip"
android:layout_gravity="fill"
android:background="#00FF00"
/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
注意android:background="#00FF00"(绿色),它只是可视化的目的.
我将它们包含在我的视图中:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
style="@style/white_background">
<include layout="@layout/header" />
(...)
Run Code Online (Sandbox Code Playgroud)
因此,当我实际尝试时,结果看起来像左图像,而不是它应该是什么样的(右):

(1)这 - 橙色 - 部分是图像/ ImageView
(2)不受欢迎的绿色边框.注意:通常,绿色区域是透明的 - 它只是绿色,因为我设置了background.
注意顶部图像周围的绿色边框; 它是ImageView的一部分,我无法弄清楚它为什么存在或我如何摆脱它.它将所有填充和边距设置为0(但是当我省略它们时结果是相同的).图像是480x64px jpeg*,我把它放在res/drawable中(不是在其中一个中drawable-Xdpi).
(*jpeg,因为我似乎偶然发现了旧的png伽玛问题 - 起初我通过使绿色边框与图片橙色相同来解决问题,并且颜色不匹配.)
我在我的htc desire/2.2/Build 2.33.163.1和模拟器上试了一下.我也向#android-dev中的某个人描述了这个问题.她可以重现这个问题,但也没有解释.构建目标是1.6.
更新@tehgoose:此代码产生完全相同的顶部+底部填充结果.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
style="@style/white_background">
<!-- <include layout="@layout/header" /> --> …Run Code Online (Sandbox Code Playgroud) 我看到很多应用程序使用全屏图像作为背景.这是一个例子:

我想在一个项目中使用它,到目前为止我发现的最好方法是使用大尺寸的图像,将其放入ImageView并用于android: adjustViewBounds="true"调整边距
问题是如果分辨率非常高的屏幕,图像不足.
我想到的另一个选择是在a中使用图像FrameLayout,使用match_parentin width和heightas作为背景...这会拉伸图像,但我认为结果不是很好.
你会怎么做?
我不能告诉之间的区别ImageView.ScaleType.CENTER_INSIDE和ImageView.ScaleType.FIT_CENTER.
CENTER_INSIDE
均匀缩放图像(保持图像的纵横比),使图像的尺寸(宽度和高度)等于或小于视图的相应尺寸(减去填充).
FIT_CENTER
计算将保持原始src宽高比的比例,但也将确保src完全适合dst.至少一个轴(X或Y)将完全适合.结果集中在dst内.
有人可以阐明两者之间的差异吗?
我有一个imageview高度和宽度设置为fill_parent具有linearlayout相同值设置的.所以我想这应该设置我的图像以适应屏幕.但它只适合80%(横向模式中的上下边距).
我尝试了以下代码但没有成功:
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
imgView.setMinimumWidth(width);
imgView.setMinimumHeight(height);
imgView.setMaxWidth(width);
imgView.setMaxHeight(height);
Run Code Online (Sandbox Code Playgroud)
还有其他想法吗?