Java 边框不显示在我的图像中

Java 边框不显示在我的图像中,java,android,border,Java,Android,Border,“我的图库”显示我的图像,但我不知道如何区分所选图像和其他图像。。我想在我的图像中设置边界线…现在我附上我的屏幕截图帮助我 我的截图: 我希望emulator中有这种类型的屏幕: package videothumb.videothumb; 导入android.app.Activity; 导入android.content.Context; 导入android.content.Intent; 导入android.database.Cursor; 导入android.graphics.Bitm

“我的图库”显示我的图像,但我不知道如何区分所选图像和其他图像。。我想在我的图像中设置边界线…现在我附上我的屏幕截图帮助我

我的截图:

我希望emulator中有这种类型的屏幕:

package videothumb.videothumb;
导入android.app.Activity;
导入android.content.Context;
导入android.content.Intent;
导入android.database.Cursor;
导入android.graphics.Bitmap;
导入android.os.Bundle;
导入android.provider.MediaStore;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.AdapterView;
导入android.widget.BaseAdapter;
导入android.widget.Gallery;
导入android.widget.ImageView;
导入android.widget.ListView;
导入android.widget.TextView;
导入android.widget.Toast;
导入android.widget.AdapterView.OnItemClickListener;
导入android.net.Uri;
导入android.view.Window;
导入android.view.WindowManager;
导入android.graphics.Color;
公共课视频活动{
私有最终静态Uri媒体\u外部内容\u Uri=
MediaStore.Video.Media.EXTERNAL\u CONTENT\u URI;
私有最终静态字符串_ID=MediaStore.Video.Media._ID;
私有最终静态字符串MEDIA_DATA=MediaStore.Video.MEDIA.DATA;
//用于图像选择的标志
私人画廊;;
私有游标_游标;
私有整数索引;
私有int[]\u videosId;
私有Uri _contentUri;
私有int视频列索引;
//私有静态最终整数菜单\u ID\u ZOOM=0;
保护上下文(protectedcontext)上下文;;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
_context=getApplicationContext();
setContentView(R.layout.main);
//为库设置GridView
_画廊=(画廊)findViewById(R.id.videoGrdVw);
//将默认值设置为外部/SD卡uri
_contentUri=媒体\外部\内容\ URI;
//初始化视频uri
//showtoos(_contentUri.getPath());
initVideosId();
//设置多媒体资料适配器
setGalleryAdapter();
}
私有void setGalleryAdapter(){
_gallery.setAdapter(新的VideoGalleryAdapter(_上下文));
_画廊。SetonimeClickListener(videogridlistener);
}
私有void initVideosId(){
尝试
{
//在这里,我们设置了一个字符串数组,其中包含要返回的缩略图ID列
字符串[]proj={u ID};
//现在,我们创建指向外部缩略图存储的光标
_游标=managedQuery(_contentUri,
proj,//返回哪些列
null,//WHERE子句;返回哪些行(所有行)
null,//WHERE子句选择参数(无)
null);//Order by子句(按名称升序)
int count=_cursor.getCount();
System.out.println(“总计”+_cursor.getCount());
//现在我们得到缩略图id的列索引
_columnIndex=\u cursor.getColumnIndex(\u ID);
//初始化
_videosId=新整数[计数];
//将位置移动到第一个元素
_cursor.moveToFirst();

对于(int i=0;i您可以将ImageView的背景色设置为与边框颜色相同。并将ImageView的填充设置为边框大小。这将满足您的需要。

您可以将ImageView的背景色设置为与边框颜色相同。并将ImageView的填充设置为边框大小。这将满足您的需要想要。

你已经尝试过在图像中设置边框了吗?没有如何在图像中设置边框…我不知道我是android新手…你能告诉我…给我你的建议吗…请…你已经尝试过在图像中设置边框了吗?没有如何在图像中设置边框…我不知道我是android新手…你能告诉我…给我你的建议吗轻松…在src中,您必须提供自己的imageok,但我直接在java文件中创建图像视图…(ImageView imgVw=new ImageView(_context);)我没有使用xml文件…如果有任何错误,请告诉我。现在我发布了我的完整编码。ImageView imgVw=new ImageView(_context);尝试{if(convertView!=null){imgVw=(ImageView)convertView;}imgVw.setImageBitmap(getImage(_videosId[position]);imgVw.setAdjustViewBounds(true);//imgVw.draw(canvas);imgVw.setLayoutParams(new Gallery.LayoutParams(150100));imgVw.setBackgroundColor(Color.WHITE);imgVw.setPadding(5,5,5,5);}好的…它工作正常…但是它的显示背景色…但是当我将一个图像切换到另一个图像时我需要边框颜色。边框也要更改我期望的类型…为此,当您选择imageview时,您必须更改背景色。在src中,您必须提供自己的imageok,但我直接在java中创建图像视图文件…(ImageView imgVw=new-ImageView(_-context);)我没有使用xml文件…如果有任何错误,请告诉我。现在我发布了我的完整编码。ImageView imgVw=new-ImageView(_-context);请尝试{if(convertView!=null){imgVw=(ImageView)convertView;}imgVw.setImageBitmap(getImage(_videosId[position]);imgVw.setAdjustViewBounds(true);//imgVw.draw(canvas);imgVw.setLayoutParams(new Gallery.LayoutParams(150100));imgVw.setBackgroundColor(Color.WHITE);imgVw.setPadding(5,5,5);}好的…它工作正常…但是它的显示背景色…但是当我将一个图像切换到另一个图像时,我需要边框颜色。边框也要更改我期望的类型…为此,您必须在选择imageview时更改背景色。
package videothumb.videothumb;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.net.Uri;
import android.view.Window;
import android.view.WindowManager;
import android.graphics.Color;

public class videothumb extends Activity{

private final static Uri MEDIA_EXTERNAL_CONTENT_URI =    
MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
private final static String _ID = MediaStore.Video.Media._ID;
private final static String MEDIA_DATA = MediaStore.Video.Media.DATA;
//flag for which one is used for images selection
private Gallery _gallery; 
private Cursor _cursor;
private int _columnIndex;
private int[] _videosId;
private Uri _contentUri;
private int video_column_index;

//private static final int MENU_ID_ZOOM = 0;


protected Context _context;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    _context = getApplicationContext();

    setContentView(R.layout.main);


    //set GridView for gallery
    _gallery = (Gallery) findViewById(R.id.videoGrdVw);
    //set default as external/sdcard uri
    _contentUri = MEDIA_EXTERNAL_CONTENT_URI;
    //initialize the videos uri 
    //showToast(_contentUri.getPath());
    initVideosId();
    //set gallery adapter
     setGalleryAdapter();
   }
private void setGalleryAdapter() {
    _gallery.setAdapter(new VideoGalleryAdapter(_context));
    _gallery.setOnItemClickListener(videogridlistener);
    }
private void initVideosId() {
    try
    {
        //Here we set up a string array of the thumbnail ID column we want to get back
        String [] proj={_ID};
        // Now we create the cursor pointing to the external thumbnail store
        _cursor = managedQuery(_contentUri,
                proj, // Which columns to return
                null,       // WHERE clause; which rows to return (all rows)
                null,       // WHERE clause selection arguments (none)
                null); // Order-by clause (ascending by name)
        int count= _cursor.getCount();
        System.out.println("total"+_cursor.getCount());
        // We now get the column index of the thumbnail id
        _columnIndex = _cursor.getColumnIndex(_ID);
        //initialize 
        _videosId = new int[count];
        //move position to first element
        _cursor.moveToFirst();            
        for(int i=0;i<count;i++)
        {            
            int id = _cursor.getInt(_columnIndex);
            //

            _videosId[i]= id;
            //
            _cursor.moveToNext();
            //
        }
    }catch(Exception ex)
    {
        showToast(ex.getMessage().toString());            
    }

    }
   protected void showToast(String msg)
   {
     Toast.makeText(_context, msg, Toast.LENGTH_LONG).show();
   }
   private OnItemClickListener videogridlistener = new OnItemClickListener() {
     public void onItemClick(AdapterView parent, View v, int position,
    long id) {
        // Now we want to actually get the data location of the file
        String [] proj={MEDIA_DATA};
        // We request our cursor again
        _cursor = managedQuery(_contentUri,
                proj, // Which columns to return
                null,       // WHERE clause; which rows to return (all rows)
                null,       // WHERE clause selection arguments (none)
                null);
          //System.gc();
         // video_column_index =    
                           _cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
          _columnIndex = _cursor.getColumnIndex(MEDIA_DATA);
            // Lets move to the selected item in the cursor
            _cursor.moveToPosition(position);

          String filename = _cursor.getString(_columnIndex);
          Intent intent = new Intent(videothumb.this, ViewVideo.class);
          intent.putExtra("videofilename", filename);
          startActivity(intent);
          showToast(filename);
         // Toast.makeText(videothumb.this, "" + position, Toast.LENGTH_SHORT).show();

         }
       };
    private class VideoGalleryAdapter extends BaseAdapter
    {
    public VideoGalleryAdapter(Context c) 
    {
        _context = c;

    }
    public int getCount() 
    {
        return _videosId.length;
    }
    public Object getItem(int position) 
    {
        return position;
    }
    public long getItemId(int position) 
    {
        return position;
    }
    public View getView(int position, View convertView, ViewGroup parent) 
    {
        ImageView imgVw= new ImageView(_context);
        try
        {
            if(convertView!=null)
            {
                imgVw= (ImageView) convertView;
            }
            imgVw.setImageBitmap(getImage(_videosId[position]));
            imgVw.setAdjustViewBounds(true);
            //imgVw.draw(canvas);
            //imgVw.setBackgroundColor(Color.BLACK);
            imgVw.setLayoutParams(new Gallery.LayoutParams(150, 100));
            imgVw.setPadding(5,5,5,5);
        }
        catch(Exception ex)
        {
            System.out.println("StartActivity:getView()-135: ex " + ex.getClass() +", 
          "+ ex.getMessage());
        }
        return imgVw;
    }

    // Create the thumbnail on the fly
    private Bitmap getImage(int id) {
    Bitmap thumb = MediaStore.Video.Thumbnails.getThumbnail(getContentResolver(),id, 
    MediaStore.Video.Thumbnails.MICRO_KIND, null);
      System.out.println("ff"+MediaStore.Video.Thumbnails.getThumbnail
     (getContentResolver(),
     id, MediaStore.Video.Thumbnails.MICRO_KIND, null));
        return thumb;
    }

     }

          }