我正在尝试将线性渐变应用于ListView.这是我的drawable xml的内容:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#3A3C39"
android:endColor="#181818"
android:angle="270"
/>
<corners android:radius="0dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
所以我将它应用于我的ListView:
android:background="@drawable/shape_background_grey"
Run Code Online (Sandbox Code Playgroud)
它可以工作,但它在模拟器和真实设备上看起来非常"带状".
有没有办法减少这种"行为"?
我需要从C++获取一个字符串列表(char*)并将其返回给Java.
我怎样才能做到这一点?
我认为一个解决方案是返回一个预定义的大字符串,如:"[item1] [item2]"并在Java上进行拆分,但它看起来不像正确的方法.
我如何修改以下FFMPEG示例代码,用于从我在Android手机中的静态图像创建视频文件.我正在使用JNI来调用ffmpeg.
JNIEXPORT void JNICALL videoEncodeExample((JNIEnv *pEnv, jobject pObj, jstring filename)
{
AVCodec *codec;
AVCodecContext *c= NULL;
int i, out_size, size, x, y, outbuf_size;
FILE *f;
AVFrame *picture;
uint8_t *outbuf, *picture_buf;
printf("Video encoding\n");
/* find the mpeg1 video encoder */
codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO);
if (!codec) {
fprintf(stderr, "codec not found\n");
exit(1);
}
c= avcodec_alloc_context();
picture= avcodec_alloc_frame();
/* put sample parameters */
c->bit_rate = 400000;
/* resolution must be a multiple of two */
c->width = 352;
c->height = 288;
/* frames …Run Code Online (Sandbox Code Playgroud) 我有Android版2.1的问题.它看起来像一个bug.
我附上了一个OnScrollListener我的listView.
我正在使用该方法onScrollStateChanged(AbsListView view, int scrollState)来监视我的listview的滚动状态.
scrollstate可以假设3个值(取自文档):
我假设SCROLL_STATE_IDLE将始终在其他两个状态之一后传递.对于Android 2.1版来说,它总是如此. SCROLL_STATE_TOUCH_SCROLL后未传递SCROLL_STATE_IDLE 如果您通过触摸停止投掷而不是让滚动自行停止,则也会出现问题.这种奇怪的行为使我的listView处于不合情理的状态.
Someonelse有同样的问题吗?建议"不那么脏"的工作?
我正在实现一个图像缓存系统来缓存下载的图像.
我的策略基于两级缓存:内存级别和磁盘级别.
我的课程类似于droidfu项目中使用的课程
我下载的图像被放入一个hashmap,Bitmap对象被包装在一个SoftRererence对象中.此外,每个图像都永久保存到磁盘.如果未找到所请求的图像
Hashmap<String,SoftReference<Bitmap>>,则将在磁盘上搜索该图像,重新加入,然后将其推回到散列图中.否则,图像将从网络下载.由于我将图像存储到物理设备momery中,因此我添加了一个检查以保留设备空间并保持在占用空间的1M以下:
private void checkCacheUsage() {
long size = 0;
final File[] fileList = new File(mCacheDirPath).listFiles();
Arrays.sort(fileList, new Comparator<File>() {
public int compare(File f1, File f2) {
return Long.valueOf(f2.lastModified()).compareTo(
f1.lastModified());
}
});
for (File file : fileList) {
size += file.length();
if (size > MAX_DISK_CACHE_SIZE) {
file.delete();
Log.d(ImageCache.class.getSimpleName(),
"checkCacheUsage: Size exceeded " + size + "("
+ MAX_DISK_CACHE_SIZE + ") wiping older file {"+file.toString()+"}");
}
}
}
Run Code Online (Sandbox Code Playgroud)
在磁盘写入后的某个时候调用此方法:
Random r = new Random(); …Run Code Online (Sandbox Code Playgroud) 我有这个布局文件的主要活动:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical"
android:id="@+id/container"
>
<LinearLayout
android:layout_height="wrap_content"
android:id="@+id/header"
android:background="@drawable/logo_bk"
android:layout_width="fill_parent"
>
<Button
android:id="@+id/btn_reload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reload"
/>
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical|center_horizontal"
>
<ImageView
android:id="@+id/ImageView01"
android:src="@drawable/logo_head"
android:scaleType="fitStart"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/center"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="1">
</FrameLayout>
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:gravity="center"
android:id="@+id/footer"
android:layout_weight="2.6"
android:background="#ffffff">
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
基本上它由一个标题,一个中心部分(android:id ="@ + id/center")和一个页脚组成.页脚包含四个动态创建的按钮.最后,它看起来像一个TabWidget,底部有标签.
每个页脚的按钮都包含一个意图/活动.
问题是:如何将我的活动开始进入FrameLayout?比如TabHost这样做:
spec = tabHost
.newTabSpec(tabTitle.toLowerCase())
.setIndicator(tabTitle,res.getDrawable(R.drawable.tab_spec))
.setContent(intent);
tabHost.addTab(spec);
Run Code Online (Sandbox Code Playgroud)