I want to have a video background on my entire screen. Everything works correctly in java: it loops etc. The problem might be in xml.
Currently I have video on a top of the screen, it looks like this: (Video is perfeclty fitted in edges)
While my purpose is to have it entirely in my screen:
Please what should i make my xml look like to achieve my goal. Thanks.
XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/home_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<VideoView
android:id="#+id/surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</FrameLayout>
First you need to set the orientation to landscape since you said you purpose is in landscape mode
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); // add it below super.oncreate
If this code not working check out this link
or your could set the orientation in manifest just google it
And change this in your xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/home_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<VideoView
android:id="#+id/surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
/>
</FrameLayout>
This question already has answers here:
Software keyboard resizes background image on Android
(16 answers)
Closed 6 months ago.
I am developing an application in which the background image get shrink on keyboard pop-up. My .xml is as follows :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:facebook="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
/**
Other stuff
*/
</RelativeLayout>
</ScrollView>
</RelativeLayout>
I searched on Google and found that, to add
android:windowSoftInputMode="stateVisible|adjustPan"
in my manifest file. But its of no use.
Edit :
My Layout before key board pop up looks like :
And after pop up like:
Please check the difference in background image. In image 1 image is in size and in image 2 background image shrink-ed. I need the footer and background get shift upward on keyboard popup.
What I am missing or doing wrong please suggest me.
Just use in your onCreate() this code:
protected void onCreate(Bundle savedInstanceState) {
...
getWindow().setBackgroundDrawableResource(R.drawable.your_image_resource);
...
}
and eliminate this line in your xml:
android:background="#drawable/background"
Read more at:
http://developer.android.com/reference/android/view/Window.html
I had faced the similar issue once, mine was solved by using the below properties in manifest use it where your activity is declared.
android:windowSoftInputMode="stateHidden|adjustResize|adjustPan"
Hey can you please try adding this
android:isScrollContainer="false"
in your ScrollView. It has solved my problem once. Might help u too.
Also, add this to your activity in manifest.xml
android:windowSoftInputMode="adjustPan"
Hope it helps..!! :)
Ok if I got your question right, you want a layout with a background and a scrollview. And when the softkeyboard pops up, you want to resize the scrollview, but keep the background at full size right?
if that's what you want than I may have found a workaround for this issue:
What you can do is make 2 activities.
Activity 1:
public class StartActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent StartApp = new Intent(this, DialogActivity.class);
startActivity(StartApp); // Launch your official (dialog) Activity
setContentView(R.layout.start); // your layout with only the background
}
}
Activity2:
public class DialogActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); // get rid of dimming
this.requestWindowFeature(Window.FEATURE_NO_TITLE); //get rid of title bar (if you want)
setContentView(R.layout.dialog); //Dialog Layout with scrollview and stuff
Drawable d = new ColorDrawable(Color.BLACK); //make dialog transparent
d.setAlpha(0);
getWindow().setBackgroundDrawable(d);
}
}
start layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/test"> //your background
</LinearLayout>
dialog layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- All your Scrollview Items -->
</LinearLayout>
</ScrollView>
</RelativeLayout>
AndroidManifest.xml
start Activity:
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
dialog Activity
android:theme="#android:style/Theme.Dialog"
android:windowSoftInputMode="adjustResize"
android:excludeFromRecents="true"
Edit:
To finish Activities at once use the following somewhere inside your DialogActivity (example: override the backbutton):
#Override
public void onBackPressed() {
Intent intent = new Intent(getApplicationContext(), StartActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
}
and in onCreate() of StartActivity:
if (getIntent().getBooleanExtra("EXIT", false)) {
finish();
}
else {
Intent StartApp = new Intent(this, TestActivity.class);
startActivity(StartApp);
}
Screenshots!
Normal
Clicked the EditText box
After Scrolled down (ps: i put textbox inside scrollview thats why its gone ;) )
I hope this will help your out ;)
I had the same issue.
Add your outer layout background inside onCreate method as show below
getWindow().setBackgroundDrawableResource(R.drawable.login_bg);
and add your outer layout as
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#4d000000"
><other code></ScrollView></RelativeLayout>
Add android:layout_weight="1" for the outer layout and don't set background in xml file
I think this helps someone
You should move the android:background="#drawable/background" in an ImageView above ScrollView. When the keyboard pops up it effectivly makes the screen smaller, and having an image as background you have no control on how it is resized/cropped.
So, assuming you want to have the image full width but keep the ascpect ratio try this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:facebook="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/background"
android:scaleType="centerCrop" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
/**
Other stuff
*/
</RelativeLayout>
</ScrollView>
</RelativeLayout>
You can try different android:scaleType values to achive your desired effect. If you want the image to be cropped from the top instead of the default middle crop, see here on how to achieve this, or try using this library
Instead of android:windowSoftInputMode="stateVisible|adjustPan", you should change to android:windowSoftInputMode="stateVisible|adjustResize". It worked for me.
Use ScrollView as Top parent.
It will be scrolled up and down automatically when you open and close keyboard.
Why don't you do like this
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:focusable="true"
android:background="#drawable/background"
android:focusableInTouchMode="true">
<RelativeLayout
android:id="#+id/relative"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
/**
Other stuff
*/
>
</RelativeLayout>
</ScrollView>
You should use the adjustResize option for the windowSoftInputMode setting on the Activity in your AndroidManifest.xml file.
i am using below view heirarchy and its working fine for me:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/rfqItemsParentScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
Hi i have created two fragments on single layout.
In layout-land :
fragments need to display horizontally.
In layout-port :
fragments need to display vertically.
Now i have to run the app on portrait mode means displaying the fragment vertically.
now i have to rotate these to landscape mode means displaying the fragments vertically only.
At the same time i have to run the app on landscape mode means displaying the fragment horizontally.now i have to rotate these to portrait mode means displaying the fragment horizontally.
But i wish to display the output like:
i have to run the app on portrait mode means displaying the fragment vertically.
now i have to rotate these to landscape mode means displaying the fragments horizontally.
At the same time i have to run the app on landscape mode means displaying the fragment horizontally.now i have to rotate these to portrait mode means displaying the fragment vertically.
How can i do ???
Why am getting the result like above.please give me any suggestions .
EDIT:
layout-land : fragment.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="#+id/_listDetails"
>
<ImageView
android:id="#+id/refresh"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_gravity="center_vertical"
android:layout_toLeftOf="#+id/pos"
android:src="#drawable/ref_off" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/layout"
android:background="#414042"
android:orientation="horizontal" >
<fragment
android:id="#+id/activity_main"
android:name="com.notch.notchbolly.MainActivity"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="0.83"
/>
<View
android:layout_width="2dp"
android:layout_height="fill_parent"
android:background="#FFFFFF"
/>
<fragment
android:id="#+id/subcate"
android:name="com.notch.notchbolly.SubCate"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
layout-port: fragment.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="#+id/_listDetails"
>
<ImageView
android:id="#+id/refresh"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_gravity="center_vertical"
android:layout_toLeftOf="#+id/pos"
android:src="#drawable/ref_off" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/layout"
android:background="#414042"
android:id="#+id/orien"
android:orientation="vertical"
>
<fragment
android:id="#+id/activity_main"
android:name="com.notch.notchbolly.MainActivity"
android:layout_width="fill_parent"
android:layout_height="200dp"
/>
<View
android:layout_width="fill_parent"
android:layout_height="3dp"
android:background="#FF0000"
/>
<fragment
android:id="#+id/subcate"
android:name="com.notch.notchbolly.SubCate"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
</RelativeLayout>
This is my AndroidListFragmentActivity:
public class AndroidListFragmentActivity extends FragmentActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment);
ImageView refresh = (ImageView) findViewById(R.id.refresh);
refresh.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent in = new Intent(AndroidListFragmentActivity.this, AndroidListFragmentActivity.class);
startActivity(in);
}
});
}
#Override
public void onConfigurationChanged ( Configuration newConfig )
{
super.onConfigurationChanged(newConfig);
}
}
Remove the android:configChanges="orientation" from the activity declaration in manifest file.
there's a thing that is really making me crazy. The layout of the screen isnt changing from land to portrait correctly.
I have two folders in my layout folder to handle the orientation thing and .xml files in it, like this:
layout\main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment
android:id="#+id/menu"
android:name="br.trebew.odonto.MenuData"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<fragment
android:id="#+id/princ"
android:name="br.trebew.odonto.FragList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
and the other:
layout-large-land\main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="290dp"
android:layout_height="fill_parent">
<fragment
android:id="#+id/menu"
android:name="br.trebew.odonto.MenuData"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<fragment
android:id="#+id/princ"
android:name="br.trebew.odonto.FragList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<fragment
android:id="#+id/fdetalhe"
android:name="br.trebew.odonto.DetalheFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
My main java class is OdontO.java, which is:
public class OdontO extends FragmentActivity implements OnDateChangeListener, OnAgendaItemClickListener {
FragList fList;
MenuData mData;
DetalheFragment frag_detalhe;
private boolean detalhesInLine;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i("LayoutOr", "Entrou no onCreate OdontO");
mData = (MenuData) getSupportFragmentManager().findFragmentById(R.id.menu);
fList = (FragList) getSupportFragmentManager().findFragmentById(R.id.princ);
frag_detalhe = (DetalheFragment) getSupportFragmentManager().findFragmentById(R.id.fdetalhe);
detalhesInLine = (frag_detalhe != null &&
(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE));
if (detalhesInLine) {
fList.enablePersistentSelection();
}
else if (frag_detalhe != null) {
frag_detalhe.getView().setVisibility(View.GONE);
}
}
If screen is portrait than rotating it changes correctlly.
The problem is the reverse. If the screen is land than rotation has no change on the layout. Infact it calls the onCreate method correctly, but the layout doesnt changes to portrait! =/
Anyone would know why?
The problem may be that your portrait is in a folder for normal-sized screens and your landscape is in a folder for large-size screens. Maybe you could change layout-large-land to just layout-land (if your device has a normal screen) or change layout to layout-large (if your device has a large screen) and see it if does anything. (Note: even if it has a large screen, putting it in layout and layout-land should still work).
I have an activity in android which I set up a button under a SurfaceView. And the result looks like this:
And I'm satisfied with it except one thing, the writing on the button is astray and must be setup correctly.
For this I used animations like this:
takePhoto = (Button) findViewById(R.id.btnPhoto);
takePhoto.setText(t);
RotateAnimation ranim = (RotateAnimation)AnimationUtils.loadAnimation(this, R.anim.myanim);
ranim.setFillAfter(true);
takePhoto.setAnimation(ranim);
WHERE the res/anim/myanim looks like:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="-90"
android:pivotX="50%"
android:pivotY="50%"
android:duration="0" />
But the result is a little bit disappointing cause the whole looks like:
The text is ok, but the dimensions are reduced.
What I want is to keep the text correctly and the initial size.How could I do that???
It has nothing to do with the button's properties in the xml file cause I haven't changed them when loading the animation....Ideas?Thanks...
EDIT: xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
>
<SurfaceView android:layout_width="450dip"
android:layout_height="fill_parent" android:id="#+id/surface_camera" />
<RelativeLayout android:layout_width="fill_parent"
android:layout_toRightOf="#id/surface_camera"
android:layout_height="fill_parent"
>
<Button android:layout_width="680dip"
android:layout_height="680dip"
android:id="#+id/btnPhoto"
android:layout_alignParentBottom="true"
android:text="Take Photo"
android:layout_gravity="bottom|right" />
</RelativeLayout>
</RelativeLayout>
IMPORTANT:
In the cases described below...my activity is in `LANDSCAPE` mode and the position of the phone is portrait.Another issue is that when I turn my phone in landscape mode(and here I mean the position of the phone, cause the activity is still landscape) the button doesn't go at the bottom of the phone is stays there.No matter how I turn the phone the button is in the same position!!!!
You should read this
Make two layout folders like follows ...
In both of folders your layout file name should be same.
In layout-port folder your layout file should look like this ...
android:layout_toRightOf="#id/surface_camera"
replaced by ...
android:layout_Below="#id/surface_camera"
as follows ...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
>
<SurfaceView android:layout_width="450dip"
android:layout_height="fill_parent" android:id="#+id/surface_camera" />
<RelativeLayout android:layout_width="fill_parent"
android:layout_toBelow="#id/surface_camera"
android:layout_height="fill_parent"
>
<Button android:layout_width="680dip"
android:layout_height="680dip"
android:id="#+id/btnPhoto"
android:layout_alignParentBottom="true"
android:text="Take Photo"
android:layout_gravity="bottom|right" />
</RelativeLayout>
</RelativeLayout>
Even this will considered as bad practice but you can also handle this manually, try this ..
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
int orientation = getResources().getConfiguration().orientation;
if(orientation == Configuration.ORIENTATION_PORTRAIT) {
setContentView(R.layout.main1);
}
else {
setContentView(R.layout.main2);
}
}
Also If you are doing this way No need to make two layout folders, but needs two layout files main1 and main2 in same folder
Yet another option ...
In manifest ...
<activity android:name=".ActivityName" android:configChanges="keyboardHidden|orientation">
+
In your Activity ...
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
int orientation = newConfig.orientation;
if(orientation == Configuration.ORIENTATION_PORTRAIT) {
setContentView(R.layout.main2);
}
else {
setContentView(R.layout.main);
}
}
Try this XML instead:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="fill_parent">
<SurfaceView android:id="#+id/surface_camera"
android:layout_width="450dip"
android:layout_height="fill_parent" />
<FrameLayout android:layout_width="fill_parent"
android:layout_toRightOf="#id/surface_camera"
android:layout_height="fill_parent">
<Button android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView android:id="#+id/btnPhoto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Take Photo" />
</FrameLayout>
</RelativeLayout>
You will rotate the Text not the button.