Displaying the captured image in full screen - android

In my application, I have to show the captured image from camera in full screen like in Snapshot. I could make the camera preview (surface view) to display in full screen. But when I display the captured image in ImageView, it is not displaying in the full screen.
Any help will be much appreciated.

1- If you want your Activity be full screen,do some thing like this:
public class ActivityName extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
(more details here)
2- If you want your ImageView be full screen,create instance of ImageView then set it as ContentView of your Activity or create a layout that image view completely covers that and set that layout as ContentView.

I set the scale type property of Image view as 'centerCrop' (android:scaleType="centerCrop"). Now its working fine.

Related

Draw a circle partially inside on a button dynamically android

My class Triangle extends from View and its method onDraw consists of:
... onDraw(){
...
drawCircle(anyx, anyy, anyradius, anypaint);
}
And the Activity in which I want to create the Button and the Circle, both created dynamically.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newexample);
RelativeLayout viewGroup = (RelativeLayout)findViewById(R.id.visiont);
Button b1 = new Button(this);
viewGroup.addView(b1);
b1.setX(140); // Position of the button
b1.setY(140);
ViewGroup.LayoutParams params = b1.getLayoutParams();
params.height=80; // Size of the button
params.width=80;
b1.setLayoutParams(params); // Deleting this does not change the behaviour of what I am getting (only changes the height and width)
Circle c = new Circle(this);
c.setColor(Color.DKGRAY);
c.setCircle(150,130,80);
viewGroup.addView(c);
}
An example of what is the desired result, the rectangle is the button.
What I am getting now is the opposite, the button is over the circle.
I tried to switch Button to ImageButton since I wanted to have a custom image in the button (Actually I wanted a clickable component)
It appears that, with only switching Button to ImageButton, works as desired, so, for me it's a suitable solution.

CustomView not showing inside ScrollView

New Android programmer here.
I'm trying to display an .png image as a bitmap on Android. The only way I have been able to display the converted image at all is with a custom class that extends View. However, my image is too large to be displayed entirely on the screen and I would like to be able to scroll with it. But when I define a ScrollView and put the Canvas with the Bitmap into it, I get a blank screen. I had no luck setting this up with the layout file, so it is all done in the Activity class.
This is where the Activity is created:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ScrollView scroll = new ScrollView(this);
scroll.addView(new CustomView(this));
setContentView(scroll);
}
And this is my CustomView class:
private class CustomView extends View{
public CustomView(Context context) {
super(context);
}
#Override
protected void onDraw(Canvas canvas){
Bitmap bitmapMap = BitmapFactory.decodeResource(getResources(),R.drawable.resourceimage);
canvas.drawBitmap(bitmapMap,0,0,null);
this.setWillNotDraw(false);
}
}
And if I replace this line of code in my Activity: setContentView(scroll)
with this line: setContentView(new CustomView(this)), I can see the image, albeit not the entire image. So, is there a way to set this up in the layout files instead? Or is there something I'm missing that I need to declare in the ScrollView class?
EDIT: I would prefer not to use ImageView, because I would like to change the image in specific locations, and using bitmap seemed to be the easiest way to accomplish that, via x and y coordinates.
Your custom view needs to override the onMeasure method and properly set the measured width and height so that the parent views (in this case the ScrollView) can know how much space to allocate for the child.

How to hide navigation bar on android

I need to enable full screen mode without navigation bar on android which placed in the bootom of the screen. (Like on clash of clans game).
I don't know how can I do this in cocos2dx. Kindly suggest.
if your question about android then that is the answer
public class FullScreen extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
if you want full screen For window (Ex: web view .....)
int width = [[NSScreen mainScreen] frame].size.width;
int height = [[NSScreen mainScreen] frame].size.height;
[yourWindow setFrame:NSMakeRect(0, 0, width, height) display:YES];
You can refer to some tutorial teach you how make your window full screen
tutorial-making-your-mac-app-support-full-screen-in-1-minute.html
ios-7-tutorial-series-gestures-and-fullscreen-layouts
https://www.youtube.com/watch?v=Bb2ywxOnFZE

Set background of android activity without using XML file

I want to develop an application in which I want to set the background image which is in my drawable folder. I want when my activity will run, the back ground will be that image.And also no XML is to be used.
Thanks.
Without XML file,
Create an ImageView and set drawable to it. Now use setContentView(View view) of Activity..
Simple...
Dynamically,
//pseudo code only.. Implement in your way..
OnCreate()
{
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.android);
setContentView(imageView);
}
Try to use setBackgroundDrawable(R.drawable.yourImage) method for your layout.Suppose your main layout is LinearLayout
LinearLayout ll = (LinearLayout) findViewById(R.id.lineaLayout);
ll.setBackgroundDrawable(R.drawable.yourImage); // like this you can set image for your layout
Another Simple solution..
Use this in your onCreate() method of Activity.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setBackgroundDrawableResource(R.drawable.background);
}
Get a handle to the root layout used, then set the background color or drawable on that. The root layout is whatever you called setContentView with.
setContentView(R.layout.main);
// Now get a handle to any View contained
// within the main layout you are using
View someView = findViewById(R.id.randomViewInMainLayout);
// Find the root view
View root = someView.getRootView()
// Set the color
root.setBackgroundColor(android.R.color.red);

how can I repeat a background image according to the text size (dynamically coming by parsing) in android

I am facing a problem in my android app. I have to dynamically find the height of the text description coming from parsing the xml and show it on an imageview(background image).
I have to repeat the backround image by finding the total height of the text.
So, Please help me that how can we find the text height dynamically and repeat the background image according to that height.
Thanks.
Since there is no answer for this question.
I tried and almost did it in the following way:
public class MainActivity extends Activity
{
String description="hello how r u this project is meant for android to calculate " +
"the size of text and can dyanamically set the image height according to the text";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
int length_count=description.length();
int window_width=getWindowManager().getDefaultDisplay().getWidth();
int lines=(length_count*14)/(window_width-30);
Log.v("length",""+length_count);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.project_dess_box_mid);
BitmapDrawable bitmapDrawable = new BitmapDrawable(bmp);
bitmapDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
LinearLayout layout = (LinearLayout)findViewById(R.id.linear1);
TextView tv=(TextView)findViewById(R.id.text01);
tv.setLines(lines);
tv.setText(description);
layout.setBackgroundDrawable(bitmapDrawable);
}
}
I posted this as it may be helpful for others too.

Categories

Resources