小编val*_*lll的帖子

Android:相机预览的屏幕方向/旋转

我创建了一个相机应用程序,我希望我的应用程序可以在所有4种可能的方向上转动,并相应地更新相机预览.因为我使用了以下我复制过的方法: Android - 相机预览是横向的

 public void updateCameraDisplay(int w, int h) {
        // set preview size and make any resize, rotate or
        // reformatting changes here

        Log.i("CameraPreviews", "Updating camera orientation with w=" + w
                + " and h=" + h);
        Parameters parameters = camera.getParameters();
        Display display = getActivity().getWindowManager()
                .getDefaultDisplay();

        int rotation = getActivity().getResources().getConfiguration().orientation;
        Log.i("CameraPreviews", "rotation is " + display.getRotation());
        if (display.getRotation() == Surface.ROTATION_0) {

            parameters.setPreviewSize(h, w);
            camera.setDisplayOrientation(0);
        }

        if (display.getRotation() == Surface.ROTATION_90) {
            parameters.setPreviewSize(w, h);
            camera.setDisplayOrientation(270);
        }

        if (display.getRotation() == Surface.ROTATION_180) …
Run Code Online (Sandbox Code Playgroud)

camera android orientation

14
推荐指数
1
解决办法
8649
查看次数

Android Studio lint.xml配置

我想在Android Studio中配置lint以忽略某些文件.我已将lint.xml文件放在app /文件夹中.这是lint文件的内容:

<?xml version="1.0" encoding="UTF-8"?>
<lint>
    <issue id="UnusedResources">
        <ignore path="res/drawable/background_palette_drawable_6.xml" />
    </issue>
</lint>
Run Code Online (Sandbox Code Playgroud)

当我运行lint来检查未使用的资源时,它仍然会将此文件视为未使用.

在app build.gradle中我有:

lintOptions {
    disable 'InvalidPackage'
    abortOnError false
    absolutePaths false
    lintConfig file('lint.xml')
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试将文件路径更改为/app/src/main/res/drawable/background_palette_drawable_6.xml 仍然无法正常工作.

我放了<issue id="UnusedResources" severity="ignore">,在这种情况下,它只是忽略所有未使用的资源,所以它似乎lint.xml找到了正确的文件,但路径可能有问题?

xml android lint

10
推荐指数
1
解决办法
7336
查看次数

Android Gallery放大/缩小

嗨我正在使用Gallery小部件来显示从互联网下载的图像.

显示几个图像,我想在人们在屏幕上上下滑动的同时进行逐渐变焦.我知道如何实现触摸事件我唯一不知道如何使整个画廊视图逐渐成长.我不想放大一张图像,我希望整个画廊逐渐放大/缩小.

编辑3:我设法缩放画廊的可见部分,但问题是我需要找到一种方式让画廊找到它并更新它的其他孩子.

会发生的情况是,如果3个图像可见,那么你开始缩放并且图库确实变小了,图像也是如此,但在这种情况下我想要的是更多图像可见但我不知道如何达到这种期望的效果.这是整个代码:

public class Gallery1 extends Activity implements OnTouchListener {

private static final String TAG = "GalleryTest";
private float zoom=0.0f;
// Remember some things for zooming
PointF start = new PointF();
PointF mid = new PointF();
Gallery g;
LinearLayout layout2;
private ImageAdapter ad;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gallery_1);
    layout2=(LinearLayout) findViewById(R.id.layout2);

    // Reference the Gallery view
    g = (Gallery) findViewById(R.id.gallery);
    // Set the adapter to our custom adapter (below)
    ad=new ImageAdapter(this);
    g.setAdapter(ad);


    layout2.setOnTouchListener(this);

} …
Run Code Online (Sandbox Code Playgroud)

android listview image zoom

7
推荐指数
1
解决办法
8754
查看次数

在Android首选项中设置应用程序语言

我希望根据用户的喜好设置应用程序语言,但到目前为止我的工作方式并不合适.

我已经设置了默认值:strings.xml以及使用西班牙语中的strings.xml的values-es.我有一个菜单选项,它将用户带到一个Preference活动,在那里他可以选择语言.

以下是代码的一些摘录:

public class Preference extends PreferenceActivity implements
        OnSharedPreferenceChangeListener {
......
// Set up a listener whenever a key changes 
        getPreferenceScreen().getSharedPreferences()
                .registerOnSharedPreferenceChangeListener(this);


...}
//(......)

//and here I have the listener so when the language pref changes value the locale gets changed.
    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
            String key) {
        if (key.equals("listPref2")) {
            String idioma = sharedPreferences.getString("listPref2", "catala");
            if ("castella".equals(idioma)) {
                idioma = "es_ES";

                Locale locale = new Locale(idioma);
                Locale.setDefault(locale);
                Configuration config = new Configuration();
                config.locale = locale;
                getApplicationContext().getResources().updateConfiguration(config,
                        getBaseContext().getResources().getDisplayMetrics()); …
Run Code Online (Sandbox Code Playgroud)

android locale localization

6
推荐指数
1
解决办法
2万
查看次数

Android中最新设备更新的Toast通知问题

这篇文章与现有的提交错误有关:

https://groups.google.com/forum/#!topic/android-developers/K7pjy3Gm5Lk/discussion

显然,在系统更新后的某些设备中,不会显示祝酒词.在首选项中,问题发生在您的应用程序中,未选中通知复选框.由于你的应用程序的所有祝酒词将被隐藏.在三星Galaxy选项卡2上发生了这种情况,但它可能发生在其他设备上:

在Nexus 7平板电脑上没有显示Toast通知

或者在谷歌小组链接上评论的SGS3上.

我不知道是否会在所有带有果冻豆的设备上发生这种情况.

建议的"修复"对我来说很好,但如果我的应用程序是由一些不知道如何操作或不想激活通知的人下载的.我依靠在应用程序中提供很多东西以告知用户一些反馈,所以我只看到一个解决方案: - >实现我自己的TOAST CLASS,不同于toast但具有相似的行为.

我已经搜索过我没有发现任何已经完成的内容所以我问是否有人发现任何自定义实现(在我自己开始编码之前)?

目标是:即使关闭此应用的通知,也要显示吐司或其替代品.

notifications android toast

5
推荐指数
1
解决办法
1001
查看次数

Android搜索域名/ FQDN

有一个错误在Android中使用一个简单的域名EJ:myservice.local等

在PC中,您可以使用nslookup并获得完整的域名,例如company.domain.com.然后,此域可用于在Android应用程序中创建套接字.

如果我在我的电脑中查看/etc/resolv.conf中有一个域名列表,那么如果我在代码中手动添加它们并逐个尝试,看看哪个有效:

protected static final String [] DNSSS = new String[] {
    "bla.bla.net",
    "aaa.bbb.net",
    "comp.com",
    "ddd.cccc.net",
    "comp.net"
};
Run Code Online (Sandbox Code Playgroud)

所以现在我的问题是:我怎样才能以更一般的方式开展工作?当然我可以添加用户设置,他们可以逐个添加他们的DNS服务器,但其他选项是什么?我怎么能解决这个问题,并以某种方式从本地网络获得这个服务器列表,但在android?

dns android fqdn

5
推荐指数
0
解决办法
2704
查看次数

在Android中无价值地改造GET

嗨,我在大多数电话中都使用Retrofit,但在某些情况下,我拥有参数中提供的完整路径。我的网址是这样的http://www.example.com/android.json。此URL已完全提供,因此我必须在运行时对其进行路径设置。我按照此处的建议实施端点 https://medium.com/@kevintcoughlin/dynamic-endpoints-with-retrofit-a1f4229f4a8d, 但在@GET中,我需要能够放置@GET(“”)。这不起作用,因为我收到一条错误消息,说我应该至少提供一个“ /”。如果我添加斜杠,则该URL变为http://www.example.com/android.json/,并且它不起作用,服务器返回禁止访问。我还尝试创建类似于此处https://github.com/square/retrofit/issues/458的自定义GET接口但使用GET且未在接口中提供value方法。然后我得到另一个错误,说值丢失了。基本上,我需要能够提供一个空值或null值,但改型不允许这样做。我该如何解决这个问题?现在,我正在手动执行json请求,但是在这种情况下是否可以使用改造?我需要传递完整的URL,无法执行端点http://www.example.com和@GET(“ / android.json”)。谢谢

android json get retrofit

5
推荐指数
2
解决办法
3172
查看次数

iphone目标C颜色

我有一个表视图,我希望单元格是替代颜色,所以我找到了这个代码:

if ((indexPath.row % 2) == 0)
    cell.backgroundColor = [UIColor greyColor];
else
    cell.backgroundColor = [UIColor whiteColor];
Run Code Online (Sandbox Code Playgroud)

它可以编译,但是当我运行应用程序时,我收到以下错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[UIColor greyColor]: unrecognized selector sent to class 0xfbad60'

好吧我通常在android中编程所以我认为默认定义了一些颜色,但似乎并非如此.我真的很新,我怎么能定义一些像color black ="000000"的颜色?有关于此的教程吗?我环顾四周但找不到任何东西.

THKS

iphone colors

4
推荐指数
1
解决办法
5820
查看次数

如何在C(linux)中挂起/重启进程

嗨,我必须为系统调用编写2个函数,这些函数将管理操作系统中的任务执行.我找不到暂停/重启进程的方法.我找到了一个信号列表,我知道kill函数,这里是我的代码:

#include <stdlib.h>
#include <signal.h>

typedef struct File
{
  int pid;
  struct File *pids;
} *file;

file file1 = NULL;

//this fonction is to suspend a process using its pid number
int V(int pid_num)
{
  //does the kill fonction just kill the process or will it take into account the signal argument?
  kill(pid_num, SIGSTOP);
  file1 = ajouter(file1, pid_num);
  return 0;
}

//this is to restart the process
int C()
{
  if (file1 != NULL)
  {
    //I know the kill fonction …
Run Code Online (Sandbox Code Playgroud)

c system process suspend

3
推荐指数
2
解决办法
1万
查看次数

Android Touch事件指针向下

嗨,我想检测两个手指何时触摸屏幕:

   case MotionEvent.ACTION_POINTER_2_DOWN: {

    twoFing=true;
    return true;
}
Run Code Online (Sandbox Code Playgroud)

问题是:

public static final int ACTION_POINTER_2_DOWN
Run Code Online (Sandbox Code Playgroud)

医生说,他被贬低了:

*getActionMasked()的常量:非主指针已经关闭.使用getActionIndex()来检索已更改的指针的索引.索引编码在getAction()返回的未屏蔽操作的ACTION_POINTER_INDEX_MASK位中.*

但我不明白如何使用它...我怎么能检测到有2个指针?如果我尝试getPointerIndex(),ActionUP和DOwn总是说只有一个指针

非常感谢

编辑:我在这里发布完整的代码,以更清楚地了解问题.我的代码正在工作,因为ACTION_POINTER_2_DOWN是一个弃用的值我想用其他东西替换它,但我不知道如何.

@SuppressWarnings("deprecation")
public boolean onTouch(View v, MotionEvent event) {

switch(event.getAction()){

case MotionEvent.ACTION_DOWN : {
     Log.i(TAG, "Action Down");
    downX = event.getX(0);
    downY = event.getY(0);
    return true;
}

case MotionEvent.ACTION_UP: {


    upX = event.getX(0);
    upY = event.getY(0);

    float deltaX = downX - upX;
    float deltaY = downY - upY;
    Log.i(TAG, "Action UP deltaX="+deltaX+", deltaY="+deltaY);



    // swipe vertical?
    if(Math.abs(deltaY) > MIN_DISTANCE && twoFing){
        twoFing=false;

        // …
Run Code Online (Sandbox Code Playgroud)

android touch

3
推荐指数
1
解决办法
7893
查看次数