i am changing my app to landscape on the click of a button but the problem is i have a list view and video view of a fixed height in portrait mode and after changing to landscape mode i only want to show the video view but videoview is shown of that height but i want to show it as full screen.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="#+id/relative2">
<VideoView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:visibility="visible"
android:id="#+id/video"
/>
<ProgressBar
android:id="#+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="invisible" />
<ImageView
android:id="#+id/full"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:src="#drawable/ic_fullscreen"
android:visibility="visible"/>
<ImageView
android:id="#+id/potrait"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:src="#drawable/ic_normal_screen"
android:visibility="invisible"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/relative2">
<ListView
android:id="#+id/play_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#color/material_blue_grey_800"
android:dividerHeight="1dp"
android:footerDividersEnabled="false"
android:visibility="visible"/>
</RelativeLayout>
and code for changing the orientation:
full.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
defaultScreenOrientationMode = getResources().getConfiguration().orientation;
defaultVideoViewParams = (RelativeLayout.LayoutParams) videoview.getLayoutParams();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
full.setVisibility(view.GONE);
potrait.setVisibility(view.VISIBLE);
play_list.setVisibility(View.GONE);
videoview.postDelayed(new Runnable() {
#Override
public void run() {
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
// mc.show(0);
}
}, 700);
}
});
potrait.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int defaultScreenOrientationMode;
potrait.setVisibility(view.INVISIBLE);
full.setVisibility(view.VISIBLE);
play_list.setVisibility(view.VISIBLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
videoview.postDelayed(new Runnable() {
#Override
public void run() {
videoview.setLayoutParams(defaultVideoViewParams);
videoview.layout(10, 10, 10, 10);
// mc.show(0);
}
}, 700);
}
});
To stop reloading activity on orientation change, write below code in manifest
<activity
android:name=".YourActivityName"
android:configChanges="orientation|screenSize">
</activity>
LinearLayout layout = /* ... */;
layout.setOrientation(LinearLayout.VERTICAL);
Related
I am creating my custom video player in android. I need requirement that when device is in portrait mode the height of VideoView is half of the screen and when i rotate device in landscape mode it should be fullScreen mode. But I cant not achieve this functionality
below is my xml code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="dp.com.player.MainActivity">
<RelativeLayout
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="#dimen/_200sdp"
android:id="#+id/video_frame">
<VideoView
android:id="#+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
<ImageView
android:id="#+id/pause"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:src="#drawable/ic_pause"
android:layout_centerInParent="true"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CC000000"
android:orientation="vertical"
android:id="#+id/layout_controller"
android:layout_alignParentBottom="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="4dip"
android:orientation="horizontal">
<TextView android:id="#+id/time_current"
android:textSize="14sp"
android:textStyle="bold"
android:paddingTop="4dip"
android:paddingLeft="4dip"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="4dip"
android:textColor="#android:color/white"/>
<SeekBar
android:id="#+id/sick_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="32dip" />
<TextView android:id="#+id/total_duration"
android:textSize="14sp"
android:textStyle="bold"
android:paddingTop="4dip"
android:paddingRight="4dip"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4dip"
android:textColor="#android:color/white"/>
<ImageView
android:id="#+id/full_screenMode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_fullscreen_white_24dp"
android:paddingTop="4dip"
android:paddingRight="4dip"
android:layout_gravity="center_horizontal|center_vertical"
android:paddingLeft="4dip"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_below="#+id/video_frame"
android:id="#+id/other_view">
</LinearLayout>
</RelativeLayout>
and below is my activity code
public class MainActivity extends AppCompatActivity {
private int brightnessValue;
ContentResolver contentResolver;
Window window;
VideoView videoView;
private String url = "http://aklearningsolutions.com/video/Nursery Rhymes.mp4";
SeekBar seekBar;
TextView maxTime,currentTime;
long totalDuration;
MediaPlayer mp;
Handler mHandler = new Handler();
LinearLayout mediaController;
RelativeLayout frameLayout;
ImageView pause,fullScreenImage;
boolean isFullscreen;
LinearLayout otherView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initialisedObject();
playVideo();
private void playVideo() {
Uri uri=Uri.parse(url.replace(" ","%20"));
videoView.setVideoURI(uri);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
updateControllerWidget(mp);
videoView.start();
}
});
}
private void initialisedObject() {
seekBar = (SeekBar)findViewById(R.id.sick_bar);
maxTime = (TextView)findViewById(R.id.total_duration);
videoView = (VideoView)findViewById(R.id.videoView);
currentTime = (TextView)findViewById(R.id.time_current);
mediaController = (LinearLayout)findViewById(R.id.layout_controller);
frameLayout = (RelativeLayout) findViewById(R.id.video_frame);
pause = (ImageView)findViewById(R.id.pause);
fullScreenImage = (ImageView)findViewById(R.id.full_screenMode);
otherView = (LinearLayout)findViewById(R.id.other_view);
}
public void fullScreenVideo(){
otherView.setVisibility(View.GONE);
frameLayout.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT));
fullScreenImage.setImageResource(R.drawable.ic_fullscreen_exit_white_24dp);
isFullscreen = true;
hideController(isFullscreen);
}
public void exitFullscreenVideo(){
fullScreenImage.setImageResource(R.drawable.ic_fullscreen_white_24dp);
isFullscreen = false;
frameLayout.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.WRAP_CONTENT));
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
exitFullscreenVideo();
}else if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE){
fullScreenVideo();
}
}
}
As I understand you want the layout to be full screen in landscape mode, if so
Create a new Layout for landscape mode in layout-land folder
Hide the ActionBar if you need to and then make the VideoView match_parent height and width wise in layout-land.
something like that
<VideoView
android:id="#+id/video"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
UPDATE:
This is not perfect, just a sample to show you how you can save the video position and then resume from there
private VideoView myVideoView;
private int position = 0;
//THEN OVERRIDE THESE TWO METHODS TO SAVE THE VIDEOVIEW Position BEFORE ACTIVITY GETS RECREATED
#Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
//HERE WE ARE SAVING VideoView SATATE
savedInstanceState.putInt("Position", myVideoView.getCurrentPosition());
myVideoView.pause();
}
#Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
//HERE WE GETTING THE Position BEFORE VIDEOVIEW WAS DESTROYED
position = savedInstanceState.getInt("Position");
myVideoView.seekTo(position);
}
You should create one more layout in layout-land directory for landscape view
Then in the new layout (landscape layout)
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"// change height to match_parent
android:orientation="vertical" >
<VideoView android:id="#+id/video"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
/>
</RelativeLayout>
If you don't want your layout recreate when rotate to landcapse, you should:
+ Detect orientation change by onConfigurationChanged method
+ Check if orientation is portrait-> change the height of RelativeLayout = 200 programmatically
+ orientation landscape -> change RelativeLayout = MATCH_PARENT
you mention android:layout_height="#dimen/_200sdp" so obviously it does not come in full screen
Create layout-land folder and put below code with same file name and same id
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<VideoView android:id="#+id/video"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
/>
</RelativeLayout>
May be becozz you have fixed your Relative Layout height
<RelativeLayout
android:layout_alignParentTop="true"
android:layout_width="match_parent"
==> android:layout_height="#dimen/_200sdp" <== here
android:id="#+id/video_frame">
make it match_parent and in videoview wrap_content
and add this Flag in your Activity
// full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
and if you want to hide the SystemUI bottom NavigationBar then use this.,
// Set the IMMERSIVE flag.
// Set the content to appear under the system bars so that the content
// doesn't resize when the system bars hide and show.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
getWindow().getDecorView().setSystemUiVisibility(uiOptions);
I'm having an issue with button click events and seekbar events not firing. When I drag on my seekbar, the slider changes position visually but there's no event being fired in my OnSeekBarChangedListener. I also have an ImageButton that should receive click events but it does not fire either. The MyView at the bottom here handles touch events properly. It holds a GLSurfaceView that I can pan around and pinch-zoom on. What could be causing the events to not fire?
Here's my layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/tec_root">
<ImageButton
android:id="#+id/button_star"
android:contentDescription="#string/star_description"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:src="#drawable/star_empty"
android:background="#00000000"
android:scaleType="fitXY"/>
<LinearLayout
android:id="#+id/view_plot"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#id/button_star"/>
<SeekBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/button_star"
android:layout_toStartOf="#id/button_star"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:progress="50"
android:layout_alignBaseline="#id/button_star"
android:id="#+id/seekbar" />
</RelativeLayout>
And here are the listeners:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity);
prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
starred = prefs.getBoolean("starred", false);
final ImageButton starButton = (ImageButton) findViewById(R.id.button_star);
starButton.setImageDrawable(ContextCompat.getDrawable(this, (starred ? R.drawable.star_filled :
R.drawable.star_empty)));
starButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
starred = !starred;
prefsEditor = prefs.edit();
prefsEditor.putBoolean("starred", starred);
prefsEditor.apply();
starButton.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(),
(starred ? R.drawable.star_filled : R.drawable.star_empty)));
}
});
((SeekBar) findViewById(R.id.seekbar)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Log.e("TEST", "Seekbar onProgressChanged called");
Toast.makeText(getApplicationContext(), "Seekbar fired", Toast.LENGTH_SHORT).show();
// respond to update
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
MyView myView = new MyView(this, points, false);
((LinearLayout) findViewById(R.id.view_plot)).addView(myView);
}
try this, replace LinearLayout with FrameLayout, it's not best at perfomance but works well
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tec_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<SeekBar
android:id="#+id/seekbar"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:background="#ABABAB"
android:layout_weight="1"
android:progress="50" />
<ImageButton
android:id="#+id/button_star"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="#00000000"
android:contentDescription="#string/star_description"
android:scaleType="fitXY"
android:src="#drawable/star_empty" />
</LinearLayout>
<FrameLayout
android:id="#+id/view_plot"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
/>
</LinearLayout>
Try changing your code to this:
MyView myView = new MyView(this, points, false);
myView.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
((LinearLayout) findViewById(R.id.view_plot)).addView(myView);
Could this be reproduced by removing the GLSurfaceView?
If so, changing SurfaceView.setZOrderOnTop might help.
http://developer.android.com/reference/android/view/SurfaceView.html#setZOrderOnTop(boolean)
there may be issue of layout design so please rearrange the components of ui.
seekbar is over imagebutton so android platform is not able to detect touch event.
set layout_below in seekbar
One possible reason for this could be touch handling in custom MyView. We have to be very careful about return value of onTouchEvent() function. Try returning "true" from your onTouchEvent() if you are consuming event else return "false".
I am using Vuforia AR sdk and want to create a button on the camera preview on the screen.
I cannot figure out where and how to add the button.
I have edit the camera_overlay_udt.xml like this.. In my layout design i have placed back button and listview.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/camera_overlay_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/headerLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#drawable/header"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/backButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#android:color/transparent"
android:src="#drawable/back" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Swipart"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
<ImageButton
android:id="#+id/arcstarButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
android:background="#android:color/transparent"
android:src="#drawable/star_button" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/favListingLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/headerLayout"
android:gravity="top"
android:orientation="horizontal"
android:visibility="visible" >
<ListView
android:id="#+id/favlist"
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_marginBottom="50dp"
android:layout_marginLeft="7dp"
android:cacheColorHint="#00000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/bottom_bar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:background="#color/overlay_bottom_bar_background"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="visible"
android:weightSum="1" >
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/overlay_bottom_bar_separators" />
<ImageButton
android:id="#+id/camera_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#null"
android:contentDescription="#string/content_desc_camera_button"
android:onClick="onCameraClick"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:src="#drawable/camera_button_background" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#id/bottom_bar"
android:background="#color/overlay_bottom_bar_separators" />
</RelativeLayout>
after that please Edit that ImageTargets.java class
private void addOverlayView(boolean initLayout) {
// Inflates the Overlay Layout to be displayed above the Camera View
LayoutInflater inflater = LayoutInflater.from(this);
mUILayouts = (RelativeLayout) inflater.inflate(
R.layout.camera_overlay_udt, null, false);
mUILayouts.setVisibility(View.VISIBLE);
// If this is the first time that the application runs then the
// uiLayout background is set to BLACK color, will be set to
// transparent once the SDK is initialized and camera ready to draw
if (initLayout) {
mUILayouts.setBackgroundColor(Color.TRANSPARENT);
}
// Adds the inflated layout to the view
addContentView(mUILayouts, new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
// Gets a reference to the bottom navigation bar
mBottomBar = mUILayouts.findViewById(R.id.bottom_bar);
// Gets a reference to the Camera button
mCameraButton = mUILayouts.findViewById(R.id.camera_button);
mCameraButton.setVisibility(View.GONE);
favButton = (ImageButton) mUILayouts.findViewById(R.id.arcstarButton);
listview = (ListView) mUILayouts.findViewById(R.id.favlist);
backButton = (ImageButton) mUILayouts.findViewById(R.id.backButton);
backButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View paramView) {
// TODO Auto-generated method stub
finish();
}
});
listview.setVisibility(View.GONE);
galleryList = SendFile.getFavourites();
if (galleryList != null) {
gridviewAdapter = new GridviewAdapter(ImageTargets.this);
listview.setAdapter(gridviewAdapter);
}
favButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (galleryList != null && galleryList.size() > 0) {
if (listview.getVisibility() == View.GONE) {
listview.setVisibility(View.VISIBLE);
} else {
listview.setVisibility(View.GONE);
}
} else {
Toast.makeText(ImageTargets.this, "Favourites not fond",
Toast.LENGTH_LONG).show();
}
}
});
listview.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> paramAdapterView,
View paramView, int positon, long paramLong) {
SendFile.setFavourite(galleryList.get(positon));
Intent intent = new Intent(ImageTargets.this,
LoadingScreen.class);
Bundle bundle = new Bundle();
bundle.putInt("x", x_Axis);
bundle.putInt("y", y_Axis);
intent.putExtras(bundle);
startActivity(intent);
finish();
}
});
showDialogHandler = new Handler() {
public void handleMessage(Message msg) {
String aResponse = msg.getData().getString("message");
if ((null != aResponse)) {
// ALERT MESSAGE
Toast.makeText(getBaseContext(),
"Server Response: " + aResponse, Toast.LENGTH_SHORT)
.show();
showAlertDialog(aResponse);
} else {
// ALERT MESSAGE
Toast.makeText(getBaseContext(),
"Not Got Response From Server.", Toast.LENGTH_SHORT)
.show();
}
};
};
loadingDialogHandler.captureButtonContainer = mUILayouts
.findViewById(R.id.camera_button);
mUILayouts.bringToFront();
}
They showing there layouts using handlers
Start you camera preview in a normal way. Place a layout on top of it with transparent background like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#ff000000"
android:layout_height="match_parent">
<ImageView
android:id="#+id/start_image_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:scaleType="fitXY"
android:layout_weight="1"
android:src="#drawable/scan_image"/>
</RelativeLayout>
In java file, you can add this layout like this:
private View mStartupView;
mStartupView = getLayoutInflater().inflate(
R.layout.startup_screen, null);
// Add it to the content view:
addContentView(mStartupView, new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
This way you will get to see your button on top of camera preview. Hope it helps
You can add buttons in cameraoverlay layout which is in layout folder and you can initialize buttons in initAR function which is in mainactivity.
Step 1: Add the button in the camera_overlay.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/camera_overlay_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ProgressBar
style="#android:style/Widget.ProgressBar"
android:id="#+id/loading_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:layout_marginTop="51dp"
android:text="Button" />
</RelativeLayout>
Step 2: Edit the ImageTargets.java class
private static final String LOGTAG = "ImageTargets";
private Button b1;
Step 3: Modify the initApplicationAR() function of ImageTargets.java class
private void initApplicationAR()
{
// Create OpenGL ES view:
int depthSize = 16;
int stencilSize = 0;
boolean translucent = Vuforia.requiresAlpha();
mGlView = new SampleApplicationGLView(this);
mGlView.init(translucent, depthSize, stencilSize);
mRenderer = new ImageTargetRenderer(this, vuforiaAppSession);
mRenderer.setTextures(mTextures);
mGlView.setRenderer(mRenderer);
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
b1.setVisibility(View.GONE);
}
});
}
Now lay back and watch your button disappear on a click!
Although it's a long time since the post.. yet I found one article.. wherein you can have the desired thing..
Ref: https://medium.com/nosort/adding-views-on-top-of-unityplayer-in-unityplayeractivity-e76240799c82
Solution:
Step1: Make a custom layout XML file (vuforia_widget_screen.xml). For example, button has been added.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_layout">
<FrameLayout
android:id="#+id/unity_player_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#null"
android:text="#string/welcome" />
</FrameLayout>
Step 2: Make following changes in the UnityPlayerActivity.java
Replace "setContentView(mUnityPlayer);" with
setContentView(R.layout.vuforia_widget_screen);
FrameLayout frameLayout = findViewById(R.id.unity_player_layout);
frameLayout.addView(mUnityPlayer.getView());
-> For anyone, who will face the issue in future. :)
this is my xml file:
<LinearLayout 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/videoactivity"
>
<FrameLayout android:id="#+id/videoContainer"
android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_weight="4"
android:background="#ffffff"
>
<com.schoolinsites.MediaPlayer.VideoView
android:id="#+id/videoView" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_gravity="center">
</com.schoolinsites.MediaPlayer.VideoView>
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="invisible"
/>
<com.schoolinsites.viewgroup.AdvertisementsView
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="bottom"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:id="#+id/advertisementcontrol"
></com.schoolinsites.viewgroup.AdvertisementsView>
</FrameLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/list_cardId"
android:layout_marginTop="2dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:background="#drawable/card_background"
android:layout_weight="2"
/>
</LinearLayout>
when i change the orientation of the screen, i am changing the layout properties by using the below code but the videoview is distorted after orientation change.
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(IsFullscreen)
{
}
else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
mVideo.pause();
mVideo.setBackgroundColor(R.drawable.action_search);
LinearLayout layout = (LinearLayout)findViewById(R.id.videoactivity);
layout.setOrientation(LinearLayout.HORIZONTAL);
FrameLayout bottomFrameLayout = (FrameLayout)findViewById(R.id.videoContainer);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT,1);
lp.bottomMargin = 100;
bottomFrameLayout.setLayoutParams(lp);
mVideo.start();
}
else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
{
mVideo.pause();
LinearLayout layout = (LinearLayout)findViewById(R.id.videoactivity);
layout.setOrientation(LinearLayout.VERTICAL);
FrameLayout bottomFrameLayout = (FrameLayout)findViewById(R.id.videoContainer);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT,4);
bottomFrameLayout.setLayoutParams(lp);
mVideo.start();
}
}
how to change the orientation without distorting the videoview. can any one please help me in solving the problem.
i thing's this realy if your work on 3.0+ android, in AndroidMainfest, in your activity add, android:configChanges="screenSize"
I created an animation that flips a "card" to its backside.
To achieve this, I used setRotationYBy() and setVisibility() on each, the front, and the back.
The animation itself works fine, but when the animation is running, the content of both cards disappears (and reappears when the animation is finished).
cardFront.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
final Runnable moveMapDown = new Runnable() {
public void run() {
map.animate().y(0);
}
};
final Runnable flipCard2 = new Runnable() {
public void run() {
cardBack.setVisibility(View.VISIBLE);
cardFront.setVisibility(View.INVISIBLE);
currentFront = false;
CardBack.animate().rotationYBy(90).setInterpolator
(new DecelerateInterpolator()).withEndAction(moveMapDown).setDuration(300);
cardFront.setRotationY(180);
}
};
Runnable flipCard = new Runnable() {
public void run() {
cardBack.setRotationY(-90);
cardFront.animate().rotationYBy(90).setInterpolator
(new AccelerateInterpolator()).withEndAction(flipCard2).setDuration(300);
}
};
map.animate().y(-200).withEndAction(flipCard);
}
});
XML-Layout of the backside (front almost the same).
<RelativeLayout
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageView1"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_marginTop="-18dp"
android:background="#drawable/bgpatch"
android:paddingBottom="16dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="6dp"
android:visibility="invisible" >
<RelativeLayout
android:layout_width="300dp"
android:layout_height="288dp"
android:background="#drawable/dayplan_element_bg" >
<RelativeLayout
android:id="#+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/dayplan_element_bg"
android:paddingBottom="2dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="2dp" >
<TextView
android:id="#+id/backTitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="zusätzliche Informationen"
android:textAppearance="?android:textAppearanceLarge"
android:textColor="#android:color/primary_text_dark"
android:textSize="30sp"
android:textStyle="italic" />
</RelativeLayout>
<View
android:id="#+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-1dp"
android:background="#drawable/shadow" />
</RelativeLayout>
</RelativeLayout>
Found the solution:
I had hardware-acceleration set to false due to another part of the app that requires this.
Set it back to true and it works!