Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8797429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:51:18+00:00 2026-06-13T23:51:18+00:00

just tell me how i change text view position in this code? in this

  • 0

just tell me how i change text view position in this code? in this app application show result textview at top left position of application how to i change is position to botton center or right side i try layout position in xml but is always show on top left result barcode value on same location where button present and button overlap resultText view value s o how can i change textview position?????

     package com.zijunlin.Zxing.Demo;

   import java.io.IOException;
     import java.util.Vector;

    import com.google.zxing.BarcodeFormat;
   import com.google.zxing.Result;


  import com.zijunlin.Zxing.Demo.camera.CameraManager;
  import com.zijunlin.Zxing.Demo.decoding.CaptureActivityHandler;
  import com.zijunlin.Zxing.Demo.decoding.InactivityTimer;
  import com.zijunlin.Zxing.Demo.view.ViewfinderView;

  import android.R.string;
 import android.app.Activity;
  import android.content.res.AssetFileDescriptor;
 import android.graphics.Bitmap;
  import android.media.AudioManager;
 import android.media.MediaPlayer;
 import android.media.MediaPlayer.OnCompletionListener;
  import android.os.Bundle;
 import android.os.Handler;
  import android.os.Vibrator;
 import android.view.SurfaceHolder;
 import android.view.SurfaceHolder.Callback;
 import android.view.SurfaceView;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.Button;
 import android.widget.TextView;
  import android.widget.Toast;

   public class CaptureActivity extends Activity implements Callback {

private CaptureActivityHandler handler;
private ViewfinderView viewfinderView;
private boolean hasSurface;
private Vector<BarcodeFormat> decodeFormats;
private String characterSet;
    public static TextView txtResult;
private InactivityTimer inactivityTimer;
private MediaPlayer mediaPlayer;
private boolean playBeep;
private static final float BEEP_VOLUME = 0.10f;
private boolean vibrate;
private static String barCode;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    //³õʼ»¯ CameraManager
    CameraManager.init(getApplication());

    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    txtResult = (TextView) findViewById(R.id.txtResult);

    Button mybutton = (Button) findViewById(R.id.button1);
    mybutton.setOnClickListener(new OnClickListener() {


        public void onClick(View v)

        {
            Toast.makeText(CaptureActivity.this,""+barCode, 
    Toast.LENGTH_LONG).show();
        }

    });
    hasSurface = false;
    inactivityTimer = new InactivityTimer(this);


}

@Override
protected void onResume() {
    super.onResume();
    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        initCamera(surfaceHolder);
    } else {
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }
    decodeFormats = null;
    characterSet = null;

    playBeep = true;
    AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
    if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
        playBeep = false;
    }
    initBeepSound();
    vibrate = true;
}

@Override
protected void onPause() {
    super.onPause();
    if (handler != null) {
        handler.quitSynchronously();
        handler = null;
    }
    CameraManager.get().closeDriver();
}

@Override
protected void onDestroy() {
    inactivityTimer.shutdown();
    super.onDestroy();
}

private void initCamera(SurfaceHolder surfaceHolder) {
    try {
        CameraManager.get().openDriver(surfaceHolder);
    } catch (IOException ioe) {
        return;
    } catch (RuntimeException e) {
        return;
    }
    if (handler == null) {
        handler = new CaptureActivityHandler(this, decodeFormats,
                characterSet);
    }
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {

}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    if (!hasSurface) {
        hasSurface = true;
        initCamera(holder);
    }

}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    hasSurface = false;

}

public ViewfinderView getViewfinderView() {
    return viewfinderView;
}

public Handler getHandler() {
    return handler;
}

public void drawViewfinder() {
    viewfinderView.drawViewfinder();

}

public void handleDecode(Result obj, Bitmap barcode) {
    inactivityTimer.onActivity();
    viewfinderView.drawResultBitmap(barcode);
     playBeepSoundAndVibrate();
    txtResult.setText(obj.getBarcodeFormat().toString() + ":"
            + obj.getText());


    barCode=obj.getText().toString();

    //TextView t = (TextView)findViewById(R.id.txtResult2);
    //t.setText("SEcond code here"+barCode);    
}

private void initBeepSound() {
    if (playBeep && mediaPlayer == null) {
        // The volume on STREAM_SYSTEM is not adjustable, and users 
    found      it
        // too loud,
        // so we now play on the music stream.
        setVolumeControlStream(AudioManager.STREAM_MUSIC);
        mediaPlayer = new MediaPlayer();
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mediaPlayer.setOnCompletionListener(beepListener);

        AssetFileDescriptor file = getResources().openRawResourceFd(
                R.raw.beep);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(),
                    file.getStartOffset(), file.getLength());
            file.close();
            mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
            mediaPlayer.prepare();
        } catch (IOException e) {
            mediaPlayer = null;
        }
    }
}

private static final long VIBRATE_DURATION = 200L;

private void playBeepSoundAndVibrate() {
    if (playBeep && mediaPlayer != null) {
        mediaPlayer.start();
    }
    if (vibrate) {
        Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
        vibrator.vibrate(VIBRATE_DURATION);
    }
}

/**
 * When the beep has finished playing, rewind to queue up another one.
 */
private final OnCompletionListener beepListener = new OnCompletionListener() {
    public void onCompletion(MediaPlayer mediaPlayer) {
        mediaPlayer.seekTo(0);
    }
};

  }


   <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent">

   <SurfaceView android:id="@+id/preview_view"
           android:layout_width="fill_parent"
           android:layout_gravity="center"
           android:layout_height="fill_parent"
           android:layout_centerInParent="true"/>



   <com.zijunlin.Zxing.Demo.view.ViewfinderView
  android:id="@+id/viewfinder_view"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"

  android:background="@color/transparent"/>


   <TextView android:id="@+id/txtResult"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"  
        android:layout_marginLeft="30dip"  
        android:text="hello"      
        android:textSize="14sp"/>


  <Button
    android:id="@+id/button1"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="25dip"
    android:layout_marginRight="30dip"


    android:text="Button" />





     </FrameLayout>







  package com.zijunlin.Zxing.Demo.view;

   import com.google.zxing.ResultPoint;
   import com.zijunlin.Zxing.Demo.R;
   import com.zijunlin.Zxing.Demo.camera.CameraManager;

   import android.content.Context;
   import android.content.res.Resources;
 import android.graphics.Bitmap;
  import android.graphics.Canvas;
 import android.graphics.Paint;
  import android.graphics.Rect;
 import android.util.AttributeSet;
 import android.view.View;

 import java.util.Collection;
  import java.util.HashSet;

 /**
  * This view is overlaid on top of the camera preview. It adds the viewfinder   
  rectangle and partial
  * transparency outside it, as well as the laser scanner animation and result points.
  *
 * @author dswitkin@google.com (Daniel Switkin)
 */
    public final class ViewfinderView extends View {

     private static final int[] SCANNER_ALPHA = {0, 64, 128, 192, 255, 192, 128, 64};
   private static final long ANIMATION_DELAY = 100L;
   private static final int OPAQUE = 0xFF;

  private final Paint paint;
  private Bitmap resultBitmap;
   private final int maskColor;
  private final int resultColor;
  private final int frameColor;
  private final int laserColor;
  private final int resultPointColor;
  private int scannerAlpha;
   private Collection<ResultPoint> possibleResultPoints;
   private Collection<ResultPoint> lastPossibleResultPoints;

  // This constructor is used when the class is built from an XML resource.
  public ViewfinderView(Context context, AttributeSet attrs) {
  super(context, attrs);

// Initialize these once for performance rather than calling them every time in    
 onDraw().
 paint = new Paint();
 Resources resources = getResources();
 maskColor = resources.getColor(R.color.viewfinder_mask);
 resultColor = resources.getColor(R.color.result_view);
 frameColor = resources.getColor(R.color.viewfinder_frame);
 laserColor = resources.getColor(R.color.viewfinder_laser);
 resultPointColor = resources.getColor(R.color.possible_result_points);
 scannerAlpha = 0;
 possibleResultPoints = new HashSet<ResultPoint>(5);
 }

 @Override
  public void onDraw(Canvas canvas) {
 Rect frame = CameraManager.get().getFramingRect();
 if (frame == null) {
  return;
 }
 int width = canvas.getWidth();
 int height = canvas.getHeight();

 // Draw the exterior (i.e. outside the framing rect) darkened
 paint.setColor(resultBitmap != null ? resultColor : maskColor);
 canvas.drawRect(0, 0, width, frame.top, paint);
 canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint);
canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint);
canvas.drawRect(0, frame.bottom + 1, width, height, paint);

 if (resultBitmap != null) {
  // Draw the opaque result bitmap over the scanning rectangle
  paint.setAlpha(OPAQUE);
  canvas.drawBitmap(resultBitmap, frame.left, frame.top, paint);
 } else {

  // Draw a two pixel solid black border inside the framing rect
  paint.setColor(frameColor);
  canvas.drawRect(frame.left, frame.top, frame.right + 1, frame.top + 2, paint);
  canvas.drawRect(frame.left, frame.top + 2, frame.left + 2, frame.bottom - 1, paint);
  canvas.drawRect(frame.right - 1, frame.top, frame.right + 1, frame.bottom - 1, 
  paint);
  canvas.drawRect(frame.left, frame.bottom - 1, frame.right + 1, frame.bottom + 1, 
   paint);

  // Draw a red "laser scanner" line through the middle to show decoding is active
  paint.setColor(laserColor);
  paint.setAlpha(SCANNER_ALPHA[scannerAlpha]);
  scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length;
  int middle = frame.height() / 2 + frame.top;
  canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint);

  Collection<ResultPoint> currentPossible = possibleResultPoints;
  Collection<ResultPoint> currentLast = lastPossibleResultPoints;
  if (currentPossible.isEmpty()) {
    lastPossibleResultPoints = null;
  } else {
    possibleResultPoints = new HashSet<ResultPoint>(5);
    lastPossibleResultPoints = currentPossible;
    paint.setAlpha(OPAQUE);
    paint.setColor(resultPointColor);
    for (ResultPoint point : currentPossible) {
      canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 6.0f, 
    paint);
    }
  }
  if (currentLast != null) {
    paint.setAlpha(OPAQUE / 2);
    paint.setColor(resultPointColor);
    for (ResultPoint point : currentLast) {
      canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 3.0f, 
  paint);
    }
  }

  // Request another update at the animation interval, but only repaint the laser line,
  // not the entire viewfinder mask.
  postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top, frame.right,  
 frame.bottom);
 }
 }

  public void drawViewfinder() {
 resultBitmap = null;
 invalidate();
  }

 /**
  * Draw a bitmap with the result points highlighted instead of the live scanning 
  display.
*
 * @param barcode An image of the decoded barcode.
*/
 public void drawResultBitmap(Bitmap barcode) {
 resultBitmap = barcode;
 invalidate();
 }

  public void addPossibleResultPoint(ResultPoint point) {
   possibleResultPoints.add(point);
  }

 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:51:19+00:00Added an answer on June 13, 2026 at 11:51 pm

    Use the attribute android:gravity in XML like this :

    <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:gravity="right"
            android:text="TextView" />
    

    Or if you want to change programmatically, use this :

    myTextView.setGravity(Gravity.RIGHT);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If you're just going to vote this down and not tell me how to
Suppose to have a code like this: <div class=notSelected> <label>Name <input type=text name=name id=name
can you just tell me for which type of requirement we should choose framework
I was just looking for a way to tell the OPA http server what
Is there a way to tell ifort or gfortran to just try to parse
I'm just starting PHP programming as you can tell. I want the results of
It just hit me the other day. What actually happens when I tell the
Can please some tell me when does the above written error occurs. I just
I made an app which is just working fine. It displays the number of
I am trying to change .cartSubPrice text to the new price provided by the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.