我正在准备一个像拼图一样的小游戏,因为我在布局中使用9个imageview的9个不同的图像.在启动那些是实际图像时将图像设置为imageview,在shuffle用户将滑动图像以完成拼图之后,我想用实际图像检查修改后的图像,如果它们相等或不相同则天气是否相等弹出消息像游戏一样.
我试过这样的
1.在图像之间使用AND运算符(Drawables)但不幸.
2.对图像使用setLevel(),将这些setLevel值与滑动后的图像的getLevel值进行比较仍然不吉利..这里的问题是如果我点击imageview一次getLevel()给出正确的值,如果我点击多次它给出零值.为什么会这样发生..
如果您在我的代码中发现任何错误,请帮助我,否则请指导我良好的技术..
Xml code like this
<RelativeLayout
//9 imageview's
Run Code Online (Sandbox Code Playgroud)
在这样的jave代码中,如果用户点击imageview,它将交换图像
img_View11.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(img_View21.getDrawable() == default_img ||
img_View12.getDrawable() == default_img) {
System.out.println("yes");
++click;
Noof_moves.setText("Moves: " +click);
ImageView iv = (ImageView)v;
d11 = iv.getDrawable();
prev_img = prev_imgView.getDrawable();
la11 = d11.getLevel();
System.out.println("d11 value is " +la11);
prev_imgView.setImageDrawable(d11);
img_View11.setImageDrawable(prev_img);
prev_imgView = img_View11;
check();
}
else { System.out.println("no"); }
}
});
void check(){
System.out.println("in checking condition");
if((lb11==la11) && (lb12==la12) && (lb13==la13) && (lb21==la21) && (lb22==la22)
&& …Run Code Online (Sandbox Code Playgroud) 
如何保存(如图所示)保存的部分bitmap(imageview如图所示).我需要做的就是crop a particular image使用(x,y)坐标.所有我拥有的x,y coordinates,没有别的选择cropped area.之间,用户不选择crop area.所以它足够了static.yellow part is an imageview(not the whole activity)
这个类扩展了baseadapter
public View getView(int position, View convertView, ViewGroup parent) {
if (!imagepath[position].toString().equals("no picture")) {
imageLoader.DisplayImage(imagepath[position], imageview);
}
}
public void DisplayImage(String url, ImageView imageView) {
imageViews.put(imageView, url);
Bitmap bitmap = memoryCache.get(url);
if (bitmap != null) {
imageView.setImageBitmap(bitmap);
} else {
queuePhoto(url, imageView);
}
}
Run Code Online (Sandbox Code Playgroud)
假设第一个视图应首先检查显示,但现在检查后显示.
if (!imagepath[position].toString().equals("no picture")) {
titletext.setPadding(imageview.getWidth() + 5, 0, 0, 0);
datetext.setPadding(imageview.getWidth() + 5, 0, 0, 0);
imageview.setVisibility(View.VISIBLE);
imageLoader.DisplayImage(imagepath[position], imageview);
} else {
imageview.setVisibility(View.INVISIBLE);
imageview.setImageDrawable(null);
titletext.setPadding(0, 0, 0, 0);
datetext.setPadding(0, 0, 0, 0);
}
titletext.setText(title[position].toString());
categorytext.setText(category[position].toString()); …Run Code Online (Sandbox Code Playgroud) 我想要做的是在不影响ImageView宽度的情况下更改ImageView中图像的宽度.
----------------------------------------------------------------
| |
| |
| ---------------------------------------------- |
| | | |
| | | |
| | this is the image( change its width) | |
| | | |
| ---------------------------------------------- |
| |
| this is imageView the width mustnt change |
----------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?请帮忙?
我的要求非常简单:我只想要一个带有透明绘图的相机预览.
最大的问题是alpha ="0"似乎可以工作(没有图片),但是一旦我设置了一些alpha值(甚至是"1"),图片就会显示没有透明度!
布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<android.view.SurfaceView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/preview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.view.SurfaceView>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/test"
android:alpha="5"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
码:
/***
Copyright (c) 2008-2012 CommonsWare, LLC
(..)
*/
import android.app.Activity;
import android.hardware.Camera;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.Toast;
public class PreviewDemo extends Activity {
private SurfaceView preview=null;
private SurfaceHolder previewHolder=null;
private Camera camera=null;
private boolean inPreview=false;
private boolean cameraConfigured=false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
preview=(SurfaceView)findViewById(R.id.preview);
previewHolder=preview.getHolder(); …Run Code Online (Sandbox Code Playgroud) 我正在开发我的第一个Android应用程序,我想构建一个包含两个连续图像的主菜单,然后构建一个带有某些标签的TabWidget。我正在使用Android 2.3。
我不知道为什么,但是,在图像之间,似乎出现了一些看起来很难看的空白...我一直在试图修改paddin和margin,但是没有用...有人知道会发生什么吗?
这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- android:background="#000000" -->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView android:id="@+id/TwiceBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/twice_bar"
android:scaleType="fitStart"
/>
<ImageView
android:id="@+id/Banner_publicidad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/banner_publicidad"
android:scaleType="fitStart" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</TabHost>
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助!
在我的Android应用程序中,我有一个水平列表视图和一个垂直列表视图.垂直视图包含图像.触摸任何图像时,它必须转到水平视图,但每个图像必须在同一图像视图中相互绘制并向上移动,以便显示所有图像.
谢谢
我正在制作Android应用.我有ImageView一部分代码,我需要更改其资源.我有一个String数组
String[] names = {"chair","desk"};
我的drawable文件夹中有2个图像,其名称为"chair"和"desk".我用的时候
image.setImageResource(R.drawable.chair);
它完美地运作.但我需要将其用作:
image.setImageResource(R.drawable.names[0]);
Run Code Online (Sandbox Code Playgroud)
但Java不允许我这样做.我需要将string的值发送给该方法.有没有办法做到这一点?
在我的程序中,我希望用户使用FileChooser选择要在ImageView中设置的文件.这是来自控制器的代码:
@FXML ImageView floorPlanImage;
FileChooser fileChooser;
public void loadImage()
{
System.out.println("Load Image Button Pressed");
fileChooser = new FileChooser();
File file = fileChooser.showOpenDialog(drawingAnchorPane.getScene().getWindow());
if (file != null) {
System.out.println("File Was Selected");
floorPlanImage.setImage(new Image(file.getAbsolutePath()));
}
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Load Image Button Pressed
File Was Selected
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source) …Run Code Online (Sandbox Code Playgroud) 我想将数据存储到数据库中,并希望上传可选的图像.
这意味着如果我在不添加图像的情况下插入记录,那么它将存储在没有图像名称的数据库中.
现在,当我填充数据并插入图像然后它存储在数据库中,如果我没有选择任何图像,我只添加数据,然后在数据库中没有插入数据,并在每个字段显示我的空白值
我尝试了很多,但没有得到所需的输出.
我的代码main.java
buy_image1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
selectImage();
edit.putInt("ImageID", 1);
edit.commit();
}
});
public void selectImage()
{
i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
/*i.putExtra("crop", "true");
i.putExtra("outputX", 512);
i.putExtra("outputY", 512);
i.putExtra("aspectX", 1);
i.putExtra("aspectY", 1);
i.putExtra("scale", true);
*/
}
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == getActivity().RESULT_OK && null != data) {
final int IMAGE_MAX_SIZE = 1200000; // 1.2MP
Uri selectedImage …Run Code Online (Sandbox Code Playgroud)