小编Shr*_*a S的帖子

如何将线性布局拆分为两列?

我必须将单线性布局拆分为两列(如报纸列).线性布局包含文本视图图像视图

我已经占据了屏幕宽度,并将其分成了一半,TextView然后ImageView进入第一列,即下图中的A B C 块.现在剩下的TextView并且' ImageView必须转到下一列,D E F就像它继续下去一样那么如果有人给我任何代码或想法来实现这个将是有帮助的..我尝试过GridView哪个不适合我的问题.由于TextViewImageView尺寸不明确.

在此输入图像描述

我不知道如何拆分Liner布局.我尝试像这样计算rootlayout高度

linearLayout.post(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                int linsize=linearLayout.getHeight();
                int relsize=root.getHeight();
                int textsize=txt1.getHeight();
                mainheight=relsize;
                subheight=linsize;
                Toast.makeText(getApplicationContext(), "Linerlayout "+linsize, Toast.LENGTH_LONG).show();
                Toast.makeText(getApplicationContext(), "Relative layout"+relsize, Toast.LENGTH_LONG).show();
                Toast.makeText(getApplicationContext(), "text height "+textsize, Toast.LENGTH_LONG).show();

                if(mainheight==subheight)
                {
                    Toast.makeText(getApplicationContext(), "make a new linear layout", Toast.LENGTH_LONG).show();
                    createsubview();
                }
            }
        }); 
Run Code Online (Sandbox Code Playgroud)

截图

在此输入图像描述

android android-linearlayout

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

如何在画布上画轮?

我想在画布上绘制带刻度线的圆圈. 圆圈包含100个刻度.但是在1到2之间存在比其他更多的子刻度,我还想根据用户输入(圆周旋转)计算刻度.请帮我.. 在此输入图像描述

我试过这个http://mindtherobot.com/blog/272/android-custom-ui-making-a-vintage-thermometer/

private void drawScale(Canvas canvas) {
        //canvas.drawOval(scaleRect, scalePaint);
        canvas.drawCircle(0.5f,0.5f, 0.49f,scalePaint);
        canvas.save(Canvas.MATRIX_SAVE_FLAG);
        for (i = 0; i < totalNicks; ++i) {
            float y1 = scaleRect.top;
            float y2 = y1 - 0.020f;

            //canvas.drawLine(0.5f, y1, 0.5f, y2, scalePaint);

            if (i % 1 == 0) {
                int value = nickToDegree(i);
                if(value<=360)
                {
                    float y3 = 0;
                    scaleText =new Paint();
                    scaleText.setTextSize(0.035f);
                    scaleText.setColor(Color.BLACK);
                    scaleText.setTypeface(Typeface.DEFAULT_BOLD);
                    scaleText.setTextScaleX(0.8f);
                    scaleText.setTextAlign(Paint.Align.CENTER); 
                    scaleText.setStrokeWidth(0.015f);
                    scaleText.setAntiAlias(true);

                    scaleline =new Paint();
                    scaleline.setStyle(Paint.Style.FILL);
                    scaleline.setColor(Color.BLACK);
                    scaleline.setStrokeWidth(0.005f);
                    scaleline.setAntiAlias(true);   
                    switch …
Run Code Online (Sandbox Code Playgroud)

android android-canvas

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

为什么,android中的资源在R.java中转换为HEXA-DECIMAL

为什么,资源被转换为HEXAdecimal,它是否为应用程序创建了一些对资源的快速访问.

android r.java-file

8
推荐指数
1
解决办法
1078
查看次数

是否有可能在Android中创建这种自定义视图?

在此输入图像描述

我只是想知道我是否可以在android中创建类似的布局.

自定义视图必须根据图像特性进行扩展.我试着GridView做出这种观点.

如果有人使用类似的东西让我知道.提前致谢...

android view android-layout

8
推荐指数
1
解决办法
1011
查看次数

如何根据布局的宽度显示字符串

我创建了两个垂直宽度相等的布局.我有字符串数据动态显示在文本视图上.当字符串大于布局的宽度时,字符串将被包装到布局的宽度,对于剩余的字符串,我想动态创建新的电视.此过程结束,直到剩余的字符串结束.对于下一个字符串相同的过程继 当进程到达linearlayout1的底部时,剩余的字符串应该从linearlayout2开始.并且该过程继续直到它到达linearlayout2的底部.

我试过这样的

private void nextlinechar(int numChars,String devstr) {
    nextchar=devstr;   
    Log.d("char 1",""+nextchar);
    TextView sub=new TextView(getApplicationContext());
    sub.setLines(1);
    sub.setTextColor(Color.BLACK);
    sub.setTextSize(textsize);
    sub.setText(nextchar); 
    nextchar=devstr.substring(nextcharstart);
    String textToBeSplit = nextchar; // Text you want to split between TextViews
    String data=TextMeasure(nextchar,sub);
    float myTextSize=sub.getTextSize();
    float textView2Width=400;

 // String next=TextMeasure(nextchar,sub);
    Paint paint = new Paint();    
    paint.setTextSize(myTextSize); // Your text size
    numChars1= paint.breakText(textToBeSplit, true,textView2Width, null);
    nextchar1=nextchar.substring(numChars1);
 // Log.d("char",""+i+"  "+nextchar.length());
    main.addView(sub);   
    nextlinechar(numChars1,nextchar);
}
Run Code Online (Sandbox Code Playgroud)

插图

在此输入图像描述

android textview android-layout android-linearlayout

8
推荐指数
1
解决办法
839
查看次数

为什么我应该在Android中使用匿名类而不是类重新定义?

我是Android开发人员的新手.我读了一些关于它的书.并且所有作者都强烈建议使用匿名类而不是类重新定义.

他们说

TextView txtTitle;
...
txtTitle.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {

   }
});
Run Code Online (Sandbox Code Playgroud)

比...更好

   txtTitle.setOnClickListener(new MyOnClickListener(position));
   ...

private class MyOnClickListener implements OnClickListener{
...
}
Run Code Online (Sandbox Code Playgroud)

谁能解释一下为什么?

Ofc,如果我将重新定义类用于许多不同的对象,这将是修改的问题.

但是如果我只将自己的类用于特定的对象,那么我的类的逻辑不会强烈改变,我可以使用它吗?或者我应该使用匿名课程?

android anonymous-class inner-classes

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

图像不是自动调整

在android中,当我们从库中打开截图时.模糊2秒后自动调整.

但是,当我使用此截图图像在imageview上使用图像路径设置为:,

图像路径为:/mnt/sdcard/ScreenCapture/SC20130219-124221.png

private void showImage(String imgPath) {
        // TODO Auto-generated method stub

        System.out.println("Image Path is:  "+imgPath);

        ImageView openImage=(ImageView)findViewById(R.id.img_fullScreen);
        ExifInterface exifMedia = null;
        try {
            exifMedia = new ExifInterface(imgPath);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        String exifOrint = exifMedia.getAttribute(ExifInterface.TAG_ORIENTATION);
        int exifOrientation = Integer.parseInt(exifOrint);
        System.out.println("Orientation Tag is:"+exifOrientation);
        BitmapFactory.Options mOptions=new BitmapFactory.Options();
        mOptions.inSampleSize=2;
        Bitmap imgBitmap = BitmapFactory.decodeFile(imgPath,mOptions);
        //Runtime.getRuntime().gc();

        imgBitmap = getResizedBitmapImage(imgBitmap, 200, 200, exifOrientation);
        openImage.setImageBitmap(imgBitmap);
    }
Run Code Online (Sandbox Code Playgroud)

另一种情况:从URL获取位图时:

URL url = new URL(urlTarget);
            BitmapFactory.Options mOptions = new BitmapFactory.Options(); …
Run Code Online (Sandbox Code Playgroud)

android android-imageview

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

是否可以手动销毁 SurfaceView?

即使调用了活动的 onPause,我的 SurfaceView 也不会被破坏。

我正在处理线程

public void surfaceCreated(SurfaceHolder holder) {
    if (mGameThread.getState() == Thread.State.TERMINATED) {
        createGameThread(getHolder(), getContext());
    }
    mGameThread.setRunning(true);
    mGameThread.start();
}


public void surfaceDestroyed(SurfaceHolder holder) {
    boolean retry = true;
    mGameThread.setRunning(false);
    while (retry) {
        try {
            mGameThread.join();
            retry = false;
        } catch (InterruptedException e) {
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

作为一个黑客,我必须在 onResume 中检查线程的状态,如果线程已经终止,我将完成活动

protected void onResume() {
    Log.d(mLogTag, "onResume()");
    super.onResume();
    if (mGameThread != null) {
        if (mGameThread.getState() == Thread.State.TERMINATED) {
            finish();
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

不幸的是,不可能将线程处理从surfaceDestroyed 和surfaceCreated 移动到活动的onPause() 和onResume()。是否可以在 onPause() 中手动销毁 SurfaceView 并在 …

android surfaceview

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

自定义视图未显示在水平滚动视图中不起作用

当我尝试将我的自定义视图添加到水平滚动视图时,它没有显示.但是相同的自定义视图显示在其他布局中,如相对和线性布局.

 layout=new LinearLayout(this);
        layout.setBackgroundColor(Color.YELLOW);
        layout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.MATCH_PARENT));
        layout.setOrientation(LinearLayout.HORIZONTAL);

        l = new PredicateLayout(this);
//       l.sendtext(info);
         for(int j=0;j<info.length;j++)
         {

            LinearLayout aa=new LinearLayout(this);
            aa.setOrientation(LinearLayout.VERTICAL);
            t = new TextView(this);
                t.setText(info[j]);
                t.setBackgroundColor(Color.GREEN);
                t.setTextSize(i);
                t.setWidth(screenwidth/2);
                aa.addView(t);
                l.addView(aa, new PredicateLayout.LayoutParams(0, 0));

         }

         layout.addView(l);
        scroll.addView(layout);
Run Code Online (Sandbox Code Playgroud)

我的XML看起来像这样

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/scroll"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:orientation="horizontal" 
    >

</HorizontalScrollView>
Run Code Online (Sandbox Code Playgroud)

也尝试过这样

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/scroll"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:orientation="horizontal" 
    >

    <com.test.app.PredicateLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:id="@+id/predicate_layout"
        >

    </com.omnion.bible.PredicateLayout> 
</HorizontalScrollView>
Run Code Online (Sandbox Code Playgroud)

代码看起来像

test=(PredicateLayout)findViewById(R.id.predicate_layout);

 for(int j=0;j<info.length;j++)
         {

            LinearLayout aa=new LinearLayout(this);
            aa.setOrientation(LinearLayout.VERTICAL);
            t = new TextView(this);
                t.setText(info[j]);
                t.setBackgroundColor(Color.GREEN);
                t.setTextSize(i);
                t.setWidth(screenwidth/2); …
Run Code Online (Sandbox Code Playgroud)

android android-custom-view horizontalscrollview

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

Eclipse没有找到Nexus 4或Nexus 7

我无法在Windows 7上找到我的新Nexus 4手机.之前我使用过Nexus 4,然后按照说明查找了设备,之后我又使用了另一款无法在Windows7中找到的Nexus 4手机.我也无法找到Nexus 7.

重点是,我只能找到最初安装的Nexus 4,我无法找到任何其他Nexus手机或平板电脑.任何人都可以帮我完成这件事.

谢谢

eclipse android android-emulator

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

从android开始的小时和分钟

我有java util date Thu Feb 28 15:35:00 GMT+00:00 2013

如何将其转换为HH:MM.

我试图通过下面的代码片段来做到这一点:

SimpleDateFormat formatter = new SimpleDateFormat("HH:MM");
        formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
        return formatter.format(objDate);
Run Code Online (Sandbox Code Playgroud)

它给出了正确的结果,dd mmm但总是给出02分钟HH:MM

请告诉我这个功能有什么问题?

java android android-date

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

更改微调器项目中的字体

我有ArrayAdapter有spinner项的字符串

如何务实地改变代码

注意:我知道我应该覆盖并实现View ..等,但我需要更多细节:

  Typeface font = Typeface.createFromAsset(getAssets(), "extrafine.ttf");  



    String array_spinner[];
    array_spinner=new String[3];
    array_spinner[0]="general";
    array_spinner[1]="quisiton";
    array_spinner[2]="suggsution";

    final Spinner spinner = (Spinner) findViewById( R.id.spinner1 ); 

        ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
                this, android.R.layout.simple_spinner_item, array_spinner);
        spinnerArrayAdapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );


        spinner.setAdapter(spinnerArrayAdapter);   
Run Code Online (Sandbox Code Playgroud)

java android android-spinner

0
推荐指数
1
解决办法
3486
查看次数