I have used fragments to define a simple splitview, in the right site i used a layout containing videoview the xml code is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<VideoView
android:id="#+id/tvT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
and in the left site in another fragment layout I have defined some buttons to play different videos, The program is running well in emulators, but when I run it on device, the videoview overlapped the whole area and creates a horrible look, what should I do?
You need to post more of your code if you can; what you have posted isn't really enough for people to help you. [Edit: Darn, I thought this was trivial enough to be automatically moved to a comment on the original question :-\ ]
May you could try with "fill_parent" because the video could be to big and uses the hole display:
<VideoView
android:id="#+id/tvT"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
If you can it would be good if you post some code how you setup your fragments.
Related
I have a PlayerView that takes up the top half of the Activity in portrait orientation with the bottom half of the screen showing some text.
I need to have the controller under the video without overlapping the video content (it will always be shown). By default when a user touches the video the controller appears at the bottom of the video covering the bottom part of the video. I my case I need the controller to stick under the video with no intersections with the video content.
I went through SimpleExoPlayer and PlayerView APIs but I haven't found any way to do so.
Question: How can I place the controller under the video with ExoPlayer?
Here is how the layout looks like:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.exoplayer2.ui.PlayerView
android:id="#+id/video_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#id/video_view"
android:scrollbars="vertical" />
</RelativeLayout>
This will push the controls down to the bottom of the screen:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.exoplayer2.ui.PlayerView
android:id="#+id/video_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:use_controller="false" />
<com.google.android.exoplayer2.ui.PlayerControlView
android:id="#+id/controls"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/video_view"
app:show_timeout="0" />
</RelativeLayout>
Then in Java:
PlayerView videoView = findViewById(R.id.video_view);
PlayerControlView controls = findViewById(R.id.controls);
controls.setPlayer(videoView.getPlayer());
Edit: Modified my answer to suggestion from #RashimiGautam
Refer to the answer by #Pierre.
Also to remove controller from above PlayerView, in that case, #id/video_view by writing player.showController(false) in java file.
You can also use app:use_controller:false in the xml.
So you will the only the video without controller on top. And link it to a new controller, in that case, #id/controls at the bottom of the video.
This might give you an idea, also have you tried to override the controls?
As an example, suppose we want our playback controls to consist of only a play/pause button positioned in the center of the view. We can achieve this by creating exo_playback_control_view.xml file in the application’s res/layout directory, containing:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton android:id="#id/exo_play"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:background="#CC000000"
style="#style/ExoMediaButton.Play"/>
<ImageButton android:id="#id/exo_pause"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:background="#CC000000"
style="#style/ExoMediaButton.Pause"/>
</FrameLayout>
Note that in the layout #id/exo_play and #id/exo_pause are standard ids defined by the ExoPlayer library. Use of standard ids is required so that child views can be identified, bound to the player and updated in an appropriate way. A full list of the standard ids for each view can be found in the Javadoc for PlaybackControlView and SimpleExoPlayerView. Use of each standard id is optional.
https://medium.com/google-exoplayer/customizing-exoplayers-ui-components-728cf55ee07a
I'm creating an free Android application and I'm using OpenStreetMap (OSMdroid library). I have a question. On the webpage: https://www.openstreetmap.org/copyright
I have read, that I should put a text in the corner of map activity (#OpenStreetMap contributors).
How to do this?
I'd like my app to be comply with the OSM license.
Regards
There is a built in copyright overlay for displaying the notice based on the current tile source.
Edit, sample code is below
//Copyright overlay
mCopyrightOverlay = new CopyrightOverlay(context);
mMapView.getOverlays().add(this.mCopyrightOverlay);
Basically, whatever the current tile source is, the text overlay will be drawn.
When you have your layout file simply add a TextView with "#OpenStreetMap contributors" to it. (I recommend to use a RelativeLayout)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<org.osmdroid.views.MapView android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:text="OpenStreetMap Contributors" />
</RelativeLayout>
I saw in other apps that on startup they all show this and a few seconds later it is fading out so you can use a delayed animation for that.
textView.animate().setStartDelay(3000).alpha(0).setDuration(1000).start();
I made an Activity in Android Studio and added a button in there, added the constraints so the error would go away. When I run an App from Android Studio to my phone, it works fine. When I use an AAR file in Unity and call the activity from there, the buttons jump back to 0,0 like the error said if I did not add constraints, which I did. I'm not getting any errors either as to why it's not able to constraint the button.
Here is how I made the button in my activity.
activity_main.xml
<Button
android:id="#+id/button"
android:layout_width="86dp"
android:layout_height="wrap_content"
android:layout_marginBottom="431dp"
android:layout_marginEnd="130dp"
android:layout_marginStart="168dp"
android:layout_marginTop="32dp"
android:text="#string/StringName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
I've never really worked with Android Studio UI until now, so I might have forgotten something important here, just hoping one of you guys knows what could be the problem, thanks in advance.
EDIT
The problem is with "app:", everywhere you use it should be replaced with "android:". However android:layout_constraintBottom_toEndOf="parent" doesn't work. Instead you have to use: android:layout_alignParentEnd="true". Also replace "android.support.constraint.ConstraintLayout" with "RelativeLayout".
Unity doesn't work with "app:" for some reason so replacing with "android:" is always necessary. Thanks Soon Santos for telling me about RelativeLayout, I looked at this: https://developer.android.com/guide/topics/ui/layout/relative.html and remembered I had gotten an app: problem before and fixed by changing to android:.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.Company.MainActivity">
<Button
android:id="#+id/button"
android:layout_width="86dp"
android:layout_height="wrap_content"
android:layout_marginStart="168dp"
android:layout_marginTop="25dp"
android:text="#string/StringName"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="false"/>
</RelativeLayout>
You can actually leave out android:layout_alignParentEnd/Start. With RelativeLayout it seems to not jump back to 0,0 at all, so basically always use android: and RelativeLayout when using Unity (it seems like that at least).
Nothing wrong with the code, it works for me too. Maybe it is because your other way to run the code does not support constraintLayout, you can try RelativeLayout instead and see if it'll work.
I'm working on a information orientated app using the master/detail flow and so far, so good. I would like to add images to the TextView, but it's formatted differently then what I've experienced in the past and I'm lost. from my understanding of what I've read while searching is that the scrolling text is "newer" when generating the Master/detail activity, therefore I haven't found any information on this specific issue. I would also like to pass the images in using the content activity, so it would be-
addItem(new Item(ID,Name,Detail,Image1,Image2));
what the detail XML file looks like
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/bobblehead_detail"
style="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:textIsSelectable="true"
tools:context="com.example.johnson.fallout4bobbleheadlocations.BobbleheadDetailFragment" />
I tried adding ImageView's under it, but I received errors.
tl;dr I would like to add 2 images under the scrolling TextView.
I am not sure if I clearly understand what you mean but looking at your xml it seems to me that you need to add a layout (either relative or linear) to your xml file and then add a textview and two imageviews (or whatever you want) into that layout.
Something like this:
<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"
android:padding="16dp" tools:context="com.example.somefragment">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/some_id2"
android:text="Here is your text"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/some_id"
android:src="#drawable/image1"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/some_id3"
android:src="#drawable/image2"/>
</RelativeLayout>
I've recently started working on an Android app. I'm not a programming noob, I have been programming in Java since 2009, but this is my first Android app. I have tried following some tutorials on how to set the background colour but it simply isn't working for me. I can't work out what I'm doing wrong.
In my layout directory I have files called: main.xml and view_fact.xml. They both use the linear layout and my LinearLayout Tag is as follows:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/background_grey"
>
And in my "values" directory I the contents of "strings.xml" is:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Facts</string>
<color name="background_grey">#E8E8E8</color>
</resources>
But the background colour is not changing from the default black.
I've also tried adding: "android:theme="#android:style/Theme.Light"" in my AndroidManifest.xml file.
None of this is working, any suggestions?
Thank you.
On my view_fact.xml page it looks like this:
<?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"
android:background="#color/background_grey"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Fact:"
android:padding="10dp"
android:textColor="#080808"
/>
<TextView
android:id="#+id/factData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text=""
/>
<Button
android:id="#+id/anotherFactButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Another Fact"/>
</LinearLayout>
What's interesting is that the text in "factData" is grey, while the text: "Fact:" in the Text View above is white, and I've tried to change it's colour to red and it doesn't work. It stays white.
Any suggestions? I still haven't managed to get this working; thank you.
If you want to use #color/color_name you have to create a Color.xml file and then it will be accessible in the manner you tried to use it.
Forgive the somewhat obvious questions, but: are you calling setContentView(R.layout.main) in your Activity onCreate? Is there something else in the layout that is filling the LinearLayout and covering the background grey?
Looking at the pastie you linked in the comment I think you need to remove the <?xml version="1.0" encoding="utf-8"?> line at the start. Eclipse won't build a freshly created app with that xml root in a layout..
Although that's strange as the first two examples I've found on the Android Developer site (for example) include it
I'd be interested to see what happens if you remove that line...
In Eclipse if I use
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#E8E8E8"
>
then the background colour changes.
If I change that to
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#string/background_grey"
>
by adding <string name="background_grey">#E8E8E8</string> to /res/values/strings.xml the background changes.
This also works if I declare it as android:background="#color/background_grey" in the layout and <color name="background_grey">#E8E8E8</color> in strings.xml
and if I setup res/values/colors.xml <= I've used colors.xml (while you've used color.xml) however http://developer.android.com/guide/topics/resources/more-resources.html tells us the filename is arbitrary as you can see by the declaration working in the strings.xml file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background_grey">#E8E8E8</color>
</resources>
and declare the layout as
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/background_grey"
>
then the background also changes...
If it doesn't behave the same for you then there's something funky going on or you're using a different layout than the simple example above and, well, there's something funky going on in that layout.
Okay, I've tried lots of different methods of trying to set the background colour and none of them are working. And I'm now having problems with text not updating. So I'm going to try remaking it. Using eclipse and ill make a new question if I'm still having issues. Thanks for the suggestions.