我创建了一个简单的播放图标。我将 SVG 文件导入 Android Studio 并将其作为 imageView 来源。然而,不幸的是我无法从我的 Adope XD 文档中引入下拉阴影。在这两种情况下,我一直在尝试通过代码复制下拉阴影效果。然而我一直没有成功。
我一直在搞乱现有的代码,但没有成功。这是我到目前为止所拥有的:
图片查看:
<ImageView
android:id="@+id/thumbnail_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/background_drop_shadow"
app:srcCompat="@drawable/ic_next_button_image_select" />Run Code Online (Sandbox Code Playgroud)
ic_next_button_image_select(导入的 SVG):
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="40dp"
android:height="38dp"
android:viewportWidth="40"
android:viewportHeight="38">
<path
android:pathData="M12,0L28,0A12,12 0,0 1,40 12L40,26A12,12 0,0 1,28 38L12,38A12,12 0,0 1,0 26L0,12A12,12 0,0 1,12 0z"
android:fillColor="#1ed760"/>
<path
android:pathData="M27.6,17.28a2,2 0,0 1,-0 3.439l-10.083,5.987A2,2 0,0 1,14.5 24.987L14.5,13.013a2,2 0,0 1,3.021 -1.72Z"
android:fillColor="#090909"/>
</vector>Run Code Online (Sandbox Code Playgroud)
background_drop_shadow(我找到并尝试使用的代码):
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Drop Shadow Stack -->
<item>
<shape>
<padding android:top="1dp" android:right="1dp" android:bottom="1dp" android:left="1dp" />
<stroke android:color="#02000000" android:width="1dp" …Run Code Online (Sandbox Code Playgroud)我正在尝试获取 ImageView bot 的高度和宽度,它返回 0
public class FullScreenImage extends FragmentActivity {
ImageView full_view;
int width;
int height;
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.full_screen);
full_view = (ImageView)findViewById(R.id.full_view);
Bundle bundle=getIntent().getExtras();
byte[] image= bundle.getByteArray("image");
width = full_view.getWidth();
height = full_view.getHeight();
Bitmap theImage = BitmapFactory.decodeByteArray(image, 0, image.length);
Bitmap resized = Bitmap.createScaledBitmap(theImage,width , height, true);
full_view.setImageBitmap(resized);
}
}
Run Code Online (Sandbox Code Playgroud)
请帮助我,如何从 ImageView 中找到它?
我需要通过发送参数 ( String src)设置图像资源
我有这个代码
public void getSource(View view , String src){
ImageView image = (ImageView)findViewById(R.id.img);
image.setImageURI(src);
}
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
考虑我在android的可绘制资源中有两个图像image_name1.png和image_name2.png。现在我要像下面这样设置图像
imageView.setImage(R.drawable.image_+"MyChoice"+.png);
Run Code Online (Sandbox Code Playgroud)
其中MyChoice可以是name1或name2或某些字符串
可能吗,或者我们有解决方案吗?
I am trying to implement paging in one activity but I keep running out of memory. The app runs till the 4th page but when it gets to the 5th it crashes. I've tried increasing the JVM heap size but the app still crashes at this one point where it runs out of memory to allocate.
This is my main file:
public class S1Intro extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_s1);
MyPagerAdapter adapter = new MyPagerAdapter(); …Run Code Online (Sandbox Code Playgroud) 我已经分配了一个 textview 和一个 ImageView 如下,
Text = (TextView) findViewById(R.id.TextView01);
Image = (ImageView) findViewById(R.id.ImageView01);
Run Code Online (Sandbox Code Playgroud)
现在它们的值将在我的程序中动态更改(图像从在线 url 更改),最后我需要将它们的值存储在 db 中以备将来使用。在这里我得到文本值
String TextValue = Text.getText().toString();
Run Code Online (Sandbox Code Playgroud)
但是我如何从 ImageView 存储价值?
String ImageValue = Image.someFunctionThatReturnsImageReferenceInString();
Run Code Online (Sandbox Code Playgroud)
有没有这样的功能??
或如何做到这一点.. 请帮忙
所有.我搜索过,但找不到任何可以帮我解决这个问题的东西.
由于NullPointerException,我的应用程序几乎在启动时立即退出.我怀疑问题可能是我使用可绘制图像(ImageView)而不是按钮(视图)作为你点击的东西.
谢谢你的帮助.这让我疯狂了好几个小时!
代码如下:
package com.example.imageswitchermk2;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
public class MainActivity extends Activity implements OnClickListener{
ImageView blankTile;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
blankTile = (ImageView) findViewById(R.drawable.blank);
blankTile.setOnClickListener(this); //LINE 19
}
public void onClick(View v) {
blankTile.setId(R.drawable.zero);
}
}
Run Code Online (Sandbox Code Playgroud)
和堆栈如下:
Thread [<1> main] (Suspended (exception NullPointerException))
<VM does not provide monitor information>
MainActivity.onCreate(Bundle) line: 19
MainActivity(Activity).performCreate(Bundle) line: 5231
Instrumentation.callActivityOnCreate(Activity, Bundle) line: 1087
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2148 …Run Code Online (Sandbox Code Playgroud)