相关疑难解决方法(0)

ImageView是一个动态宽度的正方形?

我有一个带有ImageViews的GridView.我每行有3个.我可以使用WRAP_CONTENT和scaleType = CENTER_CROP正确设置宽度,但我不知道如何将ImageView的大小设置为正方形.这是我到目前为止所做的,除了高度,它似乎没问题,那就是"静态":

imageView = new ImageView(context);     
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(GridView.LayoutParams.WRAP_CONTENT, 300));
Run Code Online (Sandbox Code Playgroud)

我在适配器里面做的.

size android dynamic imageview

71
推荐指数
4
解决办法
5万
查看次数

带有wrap_content高度的ImageView显示非常粗糙/裁剪的照片而不是全高

我有一个屏幕,用户可以阅读文章(顶部有大照片).

它的一般结构是:

LinearLayout -> ScrollView -> LinearLayout -> ImageViews,TextViews...etc
Run Code Online (Sandbox Code Playgroud)

我遇到问题的ImageView是顶部的大图像(在文章的标题下方,但在它的文字上方:

        <ImageView
            android:id="@+id/article_photo"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/super_light_gray"
            android:scaleType="centerCrop"
            android:contentDescription="@string/articlePhoto"
            android:cropToPadding="true"
            android:layout_marginBottom="10dp"
            android:padding="1dp"/>
Run Code Online (Sandbox Code Playgroud)

问题是,照片出现了,但是垂直裁剪很多,所以即使是垂直方向的照片也显得非常粗糙和宽阔.我认为"wrap_content"应该使它成为照片的全高......但我显然错了:)

如何让照片显示全宽(已经工作),还有全高?

我正在使用UniversalImageLoader来加载图像:

        if(lrgPhoto != null && !lrgPhoto.filepath.equals(""))
        {
            imageLoader.displayImage(
                "http://img.mysite.com/processes/resize_android.php?image=" + lrgPhoto.filepath + "&size=640&quality=90",
                imageView,
                imgDisplayOptions
                );
            imageView.setVisibility(View.VISIBLE); //show photo
        }
        else
        {
            imageView.setVisibility(View.GONE); //hide photo
            imageView.invalidate();
        }
Run Code Online (Sandbox Code Playgroud)

编辑:

如果我将'scaleType'更改为'fitXY',那么图像会显示正确的尺寸而不会被裁剪,但是它不是全宽的.有没有办法让我可以同时拥有全宽和非裁剪?

看起来"裁剪"是因为它使用图像的原始高度作为高度,但它正在放大图像以适应全宽...

xml android

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

设置按钮高度等于按钮宽度

我在互联网上看到了很多这个问题,但所有解决方案对我都不起作用..

所以这就是问题所在.我想要一个屏幕宽度为50%的按钮(工作正常).

但现在我希望它与宽度具有相同的高度.

不知怎的,这不起作用:

Button button1 = (Button) findViewById(R.id.button1);
int btnSize = button1.getLayoutParams().width;
button1.setLayoutParams(new LinearLayout.LayoutParams(btnSize, btnSize));
Run Code Online (Sandbox Code Playgroud)

请参阅以下代码:

Activity1.java:

package nl.jesse.project1;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.LinearLayout;


public class Activity1 extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_activity1);

        Button button1 = (Button) findViewById(R.id.button1);
        int btnSize = button1.getLayoutParams().width;
        System.out.println(btnSize);
        //button1.setLayoutParams(new LinearLayout.LayoutParams(btnSize, btnSize));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if …
Run Code Online (Sandbox Code Playgroud)

height android button width

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

标签 统计

android ×3

button ×1

dynamic ×1

height ×1

imageview ×1

size ×1

width ×1

xml ×1