是否可以在Android应用程序中只显示图像弹出/启动?它类似于覆盖AlertDialog的普通视图,因此它只包含一个图像而不包含任何其他内容.
解决方案: 感谢@ blessenm的帮助,我找到了答案.将活动屏蔽为对话似乎是理想的方式.以下是我使用的代码.可以根据需要调用此对话框样式活动,与启动新活动的方式相同
ImageDialog.java
public class ImageDialog extends Activity {
private ImageView mDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_dialog_layout);
mDialog = (ImageView)findViewById(R.id.your_image);
mDialog.setClickable(true);
//finish the activity (dismiss the image dialog) if the user clicks
//anywhere on the image
mDialog.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
your_dialog_layout.xml
<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/image_dialog_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:gravity = "center">
<ImageView
android:id="@+id/your_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src = "@drawable/your_image_drawable"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
为活动设置以下样式以实现此目的至关重要:
styles.xml
<style name="myDialogTheme" …Run Code Online (Sandbox Code Playgroud) 我目前有一个辅助类来执行基本的AsyncTasks,如下所示.我在需要时从活动中调用该函数.代码似乎工作正常,我没有遇到任何问题.但是,我想知道这是一个很好的编码实践,还是有任何我不知道的后果.任何反馈都会很乐意接受和赞赏.
public class OtherUtils {
public static void updatePromptsOption(final boolean showPrompt, final Context context) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
Editor preferenceEditor = PreferenceManager.getDefaultSharedPreferences(context).edit();
preferenceEditor.putBoolean(Constants.SHOW_PROMPT, showPrompt).commit();
return null;
}
}.execute();
}
}
Run Code Online (Sandbox Code Playgroud) 我试图从相机意图捕获图像,然后在其上应用图像过滤器.详细说明图像将是由相机捕获的图像,并且图像过滤器将作为png文件在资源中可用.我可以将滤镜叠加在原始图像的顶部.但是,一旦覆盖,原始图像"几乎"不可见(这意味着过滤器实际上堆叠在原始图像上而不仅仅是替换它).我有几张图片来说明我的问题.第一张图片是在Photoshop中 - 当我在图像上面放置一个滤镜时,它似乎很好.第二个图像是由下面引用的代码生成的 - 您可以清楚地看到滤镜效果丢失.有人会知道为什么会发生这样的事情.我在这里错过了一些逻辑吗?


以下是我的代码.如果您发现此处缺少任何最佳做法,我深表歉意.我最初尝试测试代码:
mPictureView = (ImageView) findViewById(R.id.pictureView);
filterButton = (Button) findViewById(R.id.filter_button1);
// define the threshold fro scaling the image
private final double SCALE_THRESHOLD = 6.0;
// acquire the bitmap (photo captured) from the Camera Intent - the uri is
// passed from a previous activity that accesses the camera and the current
// activity is used to display the bitmap
Uri imageUri = getIntent().getData();
Bitmap imageBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
// set the imageView in the current activity …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下代码动态创建WebView:
mWebView = new WebView(this);
mWebView.setId(R.id.webview);
mWebView.setVerticalScrollBarEnabled(false);
mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
mWebView.setHorizontalScrollBarEnabled(false);
mWebView.setWebViewClient(mWebViewClient);
mWebView.setWebChromeClient(mWebChromeClient);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
Run Code Online (Sandbox Code Playgroud)
但是,当我运行该程序时,我的应用程序强制退出,说明没有"setLayerType"这样的方法的错误.但是,当我通过xml创建Webview时,似乎没有问题:
<WebView android:id="@+id/webview"
android:scrollbars="none"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layerType="software" />
Run Code Online (Sandbox Code Playgroud)
我在这里使用'layertype'属性,应用程序运行正常.有人可以解释这个差异吗?有没有办法动态设置WebView的图层类型?