标签: android-imageview

如何在android中创建视频预览?

我的SD卡中有一个视频文件.我想在我的ImageView中展示这个视频的预览.请告诉我如何在Android中执行此操作.谢谢你的帮助和时间.

android android-video-player android-image android-imageview

17
推荐指数
1
解决办法
2万
查看次数

将图像裁剪为方形 - Android

如何从左右切割矩形图像(600 x 300)以适合方形ImageView?我不想调整图像大小,我只想裁剪它,为300 x 300.

[解]

正如@blackbelt所说

Bitmap cropImg = Bitmap.createBitmap(src, startX, startY, dstWidth, dstHeight);

非常适合裁剪图像.那么如何自动裁剪不同尺寸的图像.我为此创建了这个简单的代码:

// From drawable
Bitmap src= BitmapFactory.decodeResource(context.getResources(), R.drawable.image);

// From URL
Bitmap src = null;
try {
    String URL = "http://www.example.com/image.jpg";
    InputStream in = new java.net.URL(URL).openStream();
    src = BitmapFactory.decodeStream(in);
} catch (Exception e) {
    e.printStackTrace();
}

int width = src.getWidth();
int height = src.getHeight();
int crop = (width - height) / 2;
Bitmap cropImg = Bitmap.createBitmap(src, crop, 0, height, height);

ImageView.setImageBitmap(cropImg);
Run Code Online (Sandbox Code Playgroud)

android android-imageview resize-crop

17
推荐指数
3
解决办法
2万
查看次数

使图像显示在屏幕的一半

我很难让我的imageview出现在屏幕的一半,有人可以提供帮助.这是我的xml文件.它应该占用屏幕尺寸的一半,并且带有textview的线性布局应该位于imageview的页脚.

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="@drawable/fond" >

<RelativeLayout

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:layout_alignParentLeft="true"

    android:layout_below="@+id/relativeLayout1" >

    <RelativeLayout

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:layout_alignParentLeft="true" >

        <WebView

            android:id="@+id/webcontent"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:layout_alignParentLeft="true"

            android:layout_alignParentTop="true"

            android:layout_marginTop="151dp" />

    </RelativeLayout>

    <ImageView

        android:id="@+id/image_actualitedetails"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:layout_alignParentTop="true"

        android:layout_centerHorizontal="true"

        android:src="@drawable/six_yamaha" />

    <LinearLayout

        android:id="@+id/linearvideo"

        android:layout_width="fill_parent"

        android:layout_height="65dp"

        android:layout_alignBottom="@+id/image_actualitedetails"

        android:layout_alignParentLeft="true"

        android:background="#88FFFFFF"

        android:gravity="center"

        android:paddingLeft="@dimen/fourdp"

        android:paddingRight="@dimen/fourdp" >


        <TextView

            android:id="@+id/text_actualites"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="TextView"

            android:textColor="@color/tabDark"

            android:textStyle="bold" />

    </LinearLayout>


</RelativeLayout>

<RelativeLayout

    android:id="@+id/relativeLayout1"

    android:layout_width="fill_parent"

    android:layout_height="75dp"

    android:layout_alignParentLeft="true"

    android:layout_alignParentTop="true"

    android:background="@drawable/header" >

    <Button

        android:id="@+id/boutton_retour"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignParentLeft="true"

        android:layout_centerVertical="true"

        android:layout_marginLeft="14dp"

        android:background="@drawable/back" />

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

android android-imageview

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

平滑的幻灯片图像单向

我有一个对称的图像,我想从右到左顺利地移动它.我试图使用TranslateAnimation,但首先我必须正确设置我的图像这是非常困难的主要是因为这个图像使用所有屏幕宽度,我应该设置负边距.还有其他解决方案吗?是否有可能在不移动ImageView的情况下移动图像?

android android-imageview android-transitions

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

Android:从SD卡显示图像

这让我疯了!这是我的代码(我知道这个文件存在):

File imageFile = new File("/sdcard/gallery_photo_4.jpg");
ImageView jpgView = (ImageView)findViewById(R.id.imageView);
BitmapDrawable d = new BitmapDrawable(getResources(), imageFile.getAbsolutePath());
jpgView.setImageDrawable(d);
Run Code Online (Sandbox Code Playgroud)

错误发生在最后一行(第28行,如下所示).

错误输出:

W/dalvikvm(  865): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
E/AndroidRuntime(  865): FATAL EXCEPTION: main
E/AndroidRuntime(  865): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.example.camera/org.example.camera.Imgview}: java.lang.NullPointerException
E/AndroidRuntime(  865):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
E/AndroidRuntime(  865):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime(  865):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime(  865):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime(  865):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  865):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  865):    at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(  865):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  865):    at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( …
Run Code Online (Sandbox Code Playgroud)

android android-sdcard android-imageview

15
推荐指数
3
解决办法
6万
查看次数

使用ViewPager +放大ImageViews的图像库

我想要实施什么?

一个画廊使用ViewPager图像.我选择这个选项是因为图像之间的平滑过渡(我使用的是ImageView),它很好并且很容易实现.

我的问题到底是什么?

我已经能够实现所有这些,缩放不起作用.我可以在LogCat中看到它是如何打印的ZOOM(代码在帖子的末尾)但图像没有放大.关于以下代码的几点说明:

  • ImageViewHelperURL.setUrlDrawable((ImageView) img, url, R.drawable.no_image);我正在使用UrlImageViewHelper从Web上异步下载图像.
  • api.getListUrls() 这是一个ArrayList,我有图片网址.
  • 我也试过使用R.drawable的ImageView而不是下载图像

    import android.content.Context;
    import android.content.Intent;
    import android.graphics.Matrix;
    import android.graphics.PointF;
    import android.os.Bundle;
    import android.support.v4.app.ActionBar;
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentActivity;
    import android.support.v4.app.FragmentManager;
    import android.support.v4.app.FragmentPagerAdapter;
    import android.support.v4.view.Menu;
    import android.support.v4.view.MenuItem;
    import android.support.v4.view.ViewPager;
    import android.util.FloatMath;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.MenuInflater;
    import android.view.MotionEvent;
    import android.view.View;
    import android.view.View.OnTouchListener;
    import android.view.ViewGroup;
    import android.view.ViewGroup.LayoutParams;
    import android.widget.Gallery;
    import android.widget.ImageView;
    import android.widget.Toast;
    
    public class Slide extends FragmentActivity {
        private ViewPager …
    Run Code Online (Sandbox Code Playgroud)

android imageview android-imageview android-viewpager

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

如何覆盖Android库项目中定义的drawable?

我有两个Android应用程序具有类似的功能,但不同的drawables和布局.

我想将所有代码和资源放在库项目中,并覆盖引用该库的两个应用程序中的一些drawable和布局.

我创建了一个引用该库的应用程序.我将所有资源从库复制到应用程序并更改了一些drawable.我也改变了一些字符串资源.当我在Eclipse中的布局编辑器中查看其中一个更改的布局时,我看到了正确的重写图像.

当我启动应用程序时,我看到我在应用程序中更改的字符串资源正确显示(库字符串被应用程序的资源覆盖),但我的ImageViews 的drawables 都取自库的资源.

我还对一些布局资源进行了更改(移动并调整了一些图像的大小).当我启动使用更改的布局的活动(源代码在库中的活动)时,我看到带有旧(库)drawable的新(应用程序)布局.

我尝试ImageView用两种方式定义s 的drawable :

  1. 在布局xml中: android:src="@drawable/image_id"

  2. 在活动的代码中:

    ImageView view = (ImageView)findViewById(R.id.viewId);
    view.setImageResource(R.drawable.image_id);
    
    Run Code Online (Sandbox Code Playgroud)

在这两种情况下,我看到的图像都来自库项目的资源,而不是应用程序.

如果我无法解决这个问题,我将不得不复制这两个应用程序中的所有代码,这将是一个耻辱.

难道我做错了什么?

android drawable android-imageview android-library

15
推荐指数
2
解决办法
6971
查看次数

高分辨率图像 - OutOfMemoryError

我正在为Galaxy S4开发一个应用程序.该应用程序的一个要求是使用包含1920x1080像素图像的SplashScreen .它是一个高质量的.jpeg图像,图像的大小约为2兆字节.

问题是我一启动应用程序就得到一个OutOfMemoryError.我很震惊,这已经发生了只有2兆字节的图像?如何解决此问题并显示图像?

不能选择更改图像的尺寸或大小.

SplashScreen.java

public class Splashscreen extends Activity {

private static final int SPLASH_DURATION = 2000;
private boolean isBackPressed = false; 

@Override
protected void onCreate(Bundle savedInstanceState) {

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splashscreen);

    Handler h = new Handler();

    h.postDelayed(new Runnable() {

        @Override
        public void run() {

            // check if the backbutton has been pressed within the splash_duration
            if(!isBackPressed) { 

                Intent i = new Intent(Splashscreen.this, MainActivity.class);
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                Splashscreen.this.startActivity(i);
                overridePendingTransition(R.anim.short_fade_in, R.anim.short_fade_out);
            }       

            finish(); …
Run Code Online (Sandbox Code Playgroud)

android image bitmap out-of-memory android-imageview

15
推荐指数
2
解决办法
1万
查看次数

ImageView.ScaleType ="MATRIX"是什么意思:Android

我知道matrix它的结构和工作有关图像视图的比例类型.但,

  1. 我找不到确切的含义ImageView.ScaleType="MATRIX".通过声明这一点,绘制图像视图时会发生什么.

  2. ImageView.ScaleType="MATRIX"什么时候可以使用?

  3. 它与FIT_END&有何不同FIT_START

我搜索了它并且还提到了官方链接,但未能找到确切的答案.

android android-layout android-imageview

15
推荐指数
1
解决办法
2万
查看次数

如何在工具栏中添加图像

我正在按照这个例子来创建我的应用程序现在我正在尝试在我的工具栏中添加图像但是图像没有显示,我正在尝试设置我的应用程序徽标,以下是我的代码和工具栏xml可以任何人告诉我什么是错误?

toolbar.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    local:theme="@style/MyMaterialTheme.Base"
    local:popupTheme="@style/ThemeOverlay.AppCompat.Light" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/toolbartitle"
        />

    </android.support.v7.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)

MainActivity.java

public class MainActivity extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener {

    private static String TAG = MainActivity.class.getSimpleName();

    private Toolbar mToolbar;
    private FragmentDrawer drawerFragment;
    private String chng;
    private Intent i;
    public SearchView searchView;
    public SearchManager searchManager;

    // Alert Dialog Manager
    AlertDialogManager alert = new AlertDialogManager();

    // Session Manager Class
    SessionManager session;

    private String id;
    private boolean b;
    private String …
Run Code Online (Sandbox Code Playgroud)

android android-imageview android-toolbar

15
推荐指数
3
解决办法
6万
查看次数