标签: android-imageview

如何缩放ImageView宽度

这是我的布局文件

<LinearLayout ...
<ImageView
    android:id="@+id/feed_image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_horizontal"
    android:adjustViewBounds="true"
    android:contentDescription="@string/image_content_description" />
Run Code Online (Sandbox Code Playgroud)

ImageView宽度与父宽度不匹配.(宽度是图像源宽度)

图像源从URL加载了延迟加载.

如何缩放图像视图无缝图像源的宽度?

我想要

宽度=匹配(或填充)父级.

高度=自动缩放

android android-layout android-imageview

1
推荐指数
1
解决办法
5485
查看次数

ImageView In Fragment 未显示

我有一个奇怪的问题,我有一个解决方法,但想知道是否有人可以解释为什么会发生这种情况以及更优雅的解决方案?

我有一个带有一系列片段的 ViewPager。Fragment 使用自己的布局,当 ImageView 添加到布局时,ImageView 不会在运行时呈现。

如果我在 Fragment 的 onCreateView 方法中为 ImageView 显式设置 imageDrawable(即使图像与布局 xml 中引用的图像相同,则图像显示正常。

这是我的片段 xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/baseRelLayout"
    android:background="@color/colorPrimary">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/flamerite_remote_6"
        android:layout_marginStart="36dp"
        android:id="@+id/remote6ButtonImage"
        android:layout_alignParentBottom="false"
        android:layout_alignStart="@+id/textView3"
        android:scaleType="fitXY"
        android:background="@color/colorPrimary"
        android:layout_alignBottom="@+id/remote9ButtonImage" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

这是我在 onCreateView 中重新设置可绘制图像的地方

public class WizardFragment extends Fragment {
    public static final String STEP_NUMBER = "STEP_NUMBER";

    public static  final WizardFragment newInstance(String message){
        WizardFragment f = new WizardFragment();
        Bundle bdl = new Bundle(1);
        bdl.putString(STEP_NUMBER,message);

        f.setArguments(bdl);
        return f;
    } …
Run Code Online (Sandbox Code Playgroud)

java android android-layout android-imageview android-fragments

1
推荐指数
1
解决办法
3252
查看次数

如何使图像在线性布局中居中?

我有一个 xml 屏幕,其中三个子线性布局位于垂直方向的父线性布局中。第一个孩子包含一个图像视图,运行应用程序时我无法查看任何图像。为什么?图片尺寸太大了吗??如果是这样......如何扩展它?但是,可以在我的设计选项卡中查看图像。Android 标准工作室。下面是我的 xml 文件的完整代码。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_sign_up"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.root.my_laoder.SignUp"
    android:orientation="vertical">

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

       <ImageView
       android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:adjustViewBounds="true"
    android:scaleType="centerInside"
    android:src="@drawable/ty"
       />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:orientation="vertical"
        android:paddingTop="50dp"


        >


        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textEmailAddress"

           />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword"

            />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="number"

            />
    </LinearLayout>

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingTop="50dp"
        >

    <Button
        android:text="Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"/>

    <Button
        android:text="Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"

        />

</LinearLayout>


</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

xml android image-scaling android-imageview

1
推荐指数
1
解决办法
7537
查看次数

尝试将其锚定在 Coordinatorlayout 中时,ImageView 处于半隐藏状态

当我尝试锚定ImageViewin时,我遇到了一个奇怪的问题AppbarLayout

在设计器中它看起来像这样:

在此处输入图片说明

当我运行应用程序时,它看起来像:

在此处输入图片说明

我的代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:descendantFocusability="beforeDescendants"
    android:fitsSystemWindows="true"
    android:focusableInTouchMode="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipChildren="true"
            app:contentScrim="@color/transparent"
            app:layout_scrollFlags="enterAlways">

            <ImageView
                android:id="@+id/banner_image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:fitsSystemWindows="true"
                android:scaleType="fitXY"
                app:layout_collapseMode="parallax"
                app:srcCompat="@color/blue"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"/>

        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <RelativeLayout
        android:id="@+id/signup_screen_form"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <TextView
            android:id="@+id/screen_label"
            android:text="@string/signup"
            android:gravity="center"
            android:textAllCaps="true"
            android:padding="@dimen/screen_label_padding"
            android:layout_alignParentTop="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <com.mypackage.android.views.register.StepIndicatorView
            android:id="@+id/step_indicator"
            android:layout_below="@id/screen_label"
            android:layout_centerHorizontal="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/steps_recycler"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/layout_bottom"
            android:layout_below="@id/step_indicator"/>

        <LinearLayout
            android:id="@id/layout_bottom"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="horizontal"
            android:padding="@dimen/bottom_layout_padding">

            <Button …
Run Code Online (Sandbox Code Playgroud)

android android-imageview android-coordinatorlayout

1
推荐指数
1
解决办法
905
查看次数

调整位图大小保持纵横比且不变形和裁剪

有没有办法在不变形的情况下调整位图大小,使其不超过 720*1280 ?较小的高度和宽度完全没问题(在较小宽度或高度的情况下空白画布很好)我尝试了这个/sf/answers/1080891801/,但它给出了扭曲的图像。有人能提出更好的解决方案吗?

android bitmap android-imageview android-bitmap

1
推荐指数
1
解决办法
4076
查看次数

使用 Picasso 从 URL 加载自定义对话框中的 iImage

我创建了一个方法,可以从 Drawable 文件夹加载图像,该方法工作正常,但是当我尝试从URL加载图像并将其设置在我的自定义布局的 Imageview 上时,它仅返回:

java.lang.IllegalArgumentException: Target must not be null.
Run Code Online (Sandbox Code Playgroud)

我的Java代码是:

public void CustomDialogLoadImage() {
    Dialog dialog = new Dialog(this);
    ImageView FF_ReceiptImage = (ImageView) dialog.findViewById(R.id.FF_ReceiptImage);
    Picasso.with(ConveyanceAmtUpdateApprove.this).load("http://i.imgur.com/DvpvklR.png").into(FF_ReceiptImage);
    dialog.setContentView(R.layout.custom_dialogbox_image);
    dialog.show(); 
}
Run Code Online (Sandbox Code Playgroud)

我的自定义对话框是:

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/FF_ReceiptImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:src="@drawable/mobile_sales_img"
        android:layout_gravity="center"
        android:background="@drawable/border"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我已经尝试了可能的方法来解决这个问题,但它已经解决了,请帮助我......

java android android-imageview

1
推荐指数
1
解决办法
742
查看次数

如何在 ShapeableImageView 及其描边之间应用间距

我正在使用ShapeableImageView

<com.google.android.material.imageview.ShapeableImageView
        android:id="@+id/myImage"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:scaleType="centerCrop"
        android:src="@drawable/larry"
        app:strokeColor="@color/red"
        app:strokeWidth="9dp"
        app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.App.CornerCircle" />
Run Code Online (Sandbox Code Playgroud)

而且画得还不错。但是,我希望视图和笔画之间有一点间距。我已经尝试过android:padding="10dp",但这似乎不起作用。

我还尝试删除笔画属性并使用此可绘制资源来设置视图的背景:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <stroke
        android:width="9dp"
        android:color="#00FF00" />
</shape>
Run Code Online (Sandbox Code Playgroud)

但边界根本没有出现。

请问,你知道我有什么办法可以实现它吗?

android view android-imageview material-components-android

1
推荐指数
1
解决办法
2371
查看次数

为什么ImageView在XML和Java测量中有所不同?

我有一个ImageView的XML:

    <ImageView
        android:id="@+id/iv"
        android:layout_width="12dp"
        android:layout_height="12dp"
        android:src="@drawable/crossy"
        android:scaleType="fitXY" />
Run Code Online (Sandbox Code Playgroud)

当我运行以下代码时:

iv = (ImageView) findViewById(R.id.iv);
Log.i("IV WxH", ""+iv.getWidth() + " " + iv.getHeight());
Run Code Online (Sandbox Code Playgroud)

LogCat 显示以下内容:

02-05 23:56:04.116: I/IV WxH(10211): 24 24

如何确保代码中的高度和宽度与XML中的高度和宽度保持一致?

java xml android android-imageview

0
推荐指数
1
解决办法
89
查看次数

以编程方式增强ImageView亮度

我有一个Android应用程序,我使用下面的代码增加图像的亮度.但这非常慢,所以有人知道在android中增强imageview图像亮度的快速方法.请记住,这是提高图像视图亮度而不是屏幕亮度

 public static Bitmap doBrightness(Bitmap src, int value) {
    //Log.e("Brightness", "Changing brightnhjh");

    int width = src.getWidth();
    int height = src.getHeight();
    Bitmap bmout = Bitmap.createBitmap(width, height, src.getConfig());
    int A, R, G, B;
    int pixel;
    for (int i = 0; i < width; i=i++) {
        for (int j = 0; j < height; j=j++) {
            pixel = src.getPixel(i, j);
            A = Color.alpha(pixel);
            R = Color.red(pixel);
            G = Color.green(pixel);
            B = Color.blue(pixel);
            R += value;
            if (R > 255) {
                R = 255; …
Run Code Online (Sandbox Code Playgroud)

optimization android android-imageview

0
推荐指数
1
解决办法
6841
查看次数

URL图片不会设置为ImageView Android

我试图将图像从url加载到我的android ImageView.但它没有为我的网址提供图片.但当我调用另一个示例网址时,它会加载到ImageView上

我的网址为空

https://192.168.100.15/HeyVoteWeb/Home/GetImage/d9cbd32c-47fc-4644-ab97-1f525c96e9ed/100000102
Run Code Online (Sandbox Code Playgroud)

此示例网址适用于我

https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png
Run Code Online (Sandbox Code Playgroud)

这是我正在处理的代码

public class GetImage extends Activity{
ImageView postpic1;
Bitmap b;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.all_posts);
    postpic1 = (ImageView) findViewById(R.id.postpic1);
    information info = new information();
    info.execute("");
}
public class information extends AsyncTask<String, String, String>
{
    @Override
    protected String doInBackground(String... arg0) {
        try
        {
            URL url = new URL("https://localhost/HeyVoteWeb/Home/GetImage/d9cbd32c-47fc-4644-ab97-1f525c96e9ed/100000102");
            InputStream is = new BufferedInputStream(url.openStream());
            b = BitmapFactory.decodeStream(is);
        } catch(Exception e){}
        return null;
    }
    @Override
    protected void onPostExecute(String result) {
        postpic1.setImageBitmap(b);

    }
}
}
Run Code Online (Sandbox Code Playgroud)

android imageview android-imageview

0
推荐指数
1
解决办法
858
查看次数