Android : Text in ForeGround of a FrameLayout (contain a googleMap) - java

Hello everyone
To start, sorry for my bad english
I first put you in position:
I'm using Java code for Android, in Eclipse.
My application needs to show a map (Google Maps V2) in a fragment to show the runner location. The map display is already achieved.
Here is my problem: I use a FrameLayout element, which contains my map and is therefore the whole page, however, my goal is to display over the map a text box centered at the bottom. I tried to use in the Foreground property option to set my text, but it does not work (application crash when arrived on the page of the map).
Here is my code fragment_carte:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mapFrameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="#id/txtViewCoureur"
tools:context=".CarteFragment" >
</FrameLayout>
I can't post an image to show you what I want because it's my first post
I tried many solutions on this forum before asking my question
Thank you for your help!

Enclose the map inside a RelativeLayout and the rest of the controls in a FrameLayout. Here is an example of one app I have:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<fragment
android:id="#+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
class="MapFragment" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_marginTop="#dimen/activity_vertical_margin" >
<EditText
android:id="#+id/mapsearchbox"
android:layout_width="match_parent"
android:layout_height="40dp"
android:alpha="0.8"
android:background="#android:color/white"
android:hint="#string/map_search"
android:imeOptions="actionSearch"
android:inputType="text"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="30dp"
android:singleLine="true"
android:textColor="#android:color/black" >
</EditText>
<Button
android:id="#+id/mapsearchbtn
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="right|center_vertical"
android:layout_margin="8dp"
android:background="#android:drawable/ic_menu_close_clear_cancel" />
</FrameLayout>
</RelativeLayout>

Related

How to highlight a selection in a view in Android with Java

So what I am trying to achieve is the following.
If a user click on one of the two images in a Framelayout, the image get highlighted (denotes that it was selected).
<FrameLayout 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:id="#+id/rootView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_centerHorizontal="true"
app:srcCompat="#drawable/field_background" />
<ImageView
android:layout_width="160dp"
android:layout_height="150dp"
android:layout_gravity="top|left"
app:srcCompat="#drawable/forty" />
<ImageView
android:layout_width="160dp"
android:layout_height="150dp"
android:layout_gravity="top|right"
app:srcCompat="#drawable/hundred" />
</androidx.cardview.widget.CardView>
</FrameLayout>
Would I need to add an other ImageView under the two ImageViews (#drawable/forty and #drawable/hundred) and then in the associated Activity reference those images and highlight them? or is it all done in the Activity view where I can add the highlight image directly there?
Im new to Android so I am having issues understanding the best path forward.
UPDATE:
Included the desired effect.

What is the right way to use two scrollviews in a single activity?

This is my current design in my main activity.
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/txtSubestacion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Subestacion"
android:textSize="18sp" />
<Spinner
android:id="#+id/spSubestacion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dropdown" />
<TextView
android:id="#+id/txtClasificacion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Clasificacion"
android:textSize="18sp" />
<Spinner
android:id="#+id/spClasificacion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dropdown" />
<ScrollView
android:id="#+id/scrollEventos"
android:layout_width="match_parent"
android:layout_height="350dp"
android:paddingTop="30dp"
android:paddingBottom="10dp">
<LinearLayout
android:id="#+id/linearEventos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
<Button
android:id="#+id/btnRegistros"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Actualizar Registros" />
</LinearLayout>
</ScrollView>
I have a second scrollview inside the first one because this one is filled with multiple labels created from code. These labels can take up a lot of space, so a scrollview is suitable for proper navigation.
The first scrollview that contains everything is so that when changing the screen in landscape mode, you can continue browsing and access all the controls that are displayed.
The problem is that when changing the screen in landscape mode, only the first scrollview works, which allows you to see all the controls correctly. However, the second scrollview showing the records cannot be moved, and therefore the records are cut.
Is there a way to freeze the first scrollview when the user wants to slide the records and allow the second scrollview to be moved?
Or is it that I should create my design differently?
Note: Everything works correctly with the screen in portrait mode. All the controls are accessible at first instance and the second scrollview can be slid correctly allowing to see the records.
I've tried working with the layout_weight property but it didn't work for me or I just didn't know how to use it.
Use this:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<!-- Other Layout or scrollView-->
</android.support.v4.widget.NestedScrollView>
Android site: NestedScroll

Exoplayer ui split the screen and add double tap to go forward/backward circular effect

I have to reproduce the following circular effect on the exoplayer.
I added two views, exo_rew and exo_ffwd.
Which automatically do go back or forward by standard setting.
This is the code I've written so far:
<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="fill_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:id="#+id/exo_rew"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:gravity="center"
android:clickable="true"
android:focusable="true"
android:background="#00000000"
android:foreground="?attr/selectableItemBackground"
tools:ignore="Orientation" />
<LinearLayout
android:id="#+id/exo_ffwd"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:layout_alignParentLeft="false"
android:layout_alignParentRight="true"
android:gravity="center"
android:clickable="true"
android:focusable="true"
android:background="#00000000"
android:foreground="?attr/selectableItemBackground"
tools:ignore="Orientation" />
<LinearLayout
android:id="#+id/play_pause_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#15ffffff"
android:gravity="center"
>
<ImageButton
android:id="#id/exo_play"
style="#style/ExoMediaButton.Play"
/>
<ImageButton
android:id="#id/exo_pause"
style="#style/ExoMediaButton.Pause"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignWithParentIfMissing="false"
android:layout_centerHorizontal="false"
android:layout_centerVertical="false"
android:gravity="center_vertical"
>
<TextView
android:id="#id/exo_position"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:text="00:00"
android:textColor="#FFBEBEBE"
android:textSize="14sp"
android:textStyle="bold"
/>
<com.google.android.exoplayer2.ui.DefaultTimeBar
android:id="#id/exo_progress"
android:layout_width="0dp"
android:layout_height="26dp"
android:layout_weight="1"
app:played_color="#4589f2"
/>
<TextView
android:id="#id/exo_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:text="2:00:00"
android:textColor="#FFBEBEBE"
android:textSize="14sp"
android:textStyle="bold"
/>
</LinearLayout>
</RelativeLayout>
There are two problems that I could not solve:
1) That each view takes half of the screen, exo_rew on the left and exo_ffwd on the right.
I could not find a way to specify in xml a layout_width equal to match_parent/2.
Is there a way?
I tried with weightSum at 1, but it does not seem to work.
2) Create the circular effect as in the image.
the doubts are better to use a canvas creating a circle or a "circle reveal" effect.
Can someone give me a hand?
Best way would be to use ConstraintLayout and add these images with constraint start, end, bottom and top and give them width of 0dp, in this way they'll just occupy the width according to their constraint.
ConstraintLayout is very powerful it will also reduce your view hierarchy. And it would help your purpose.
If you want to add the same double tap behavior like YouTube, you can use my library to achieve it. My basic approach is to override the onTouchEvent of the PlayerView to detect DoubleTapGesture (SimpleGestureDetector) and creating an overlay on top of it.
I've written an answer here already. Use the following to implement it:
0) Requirements:
Minimum SDK: 21 (could be lower, but I've not tested older versions yet)
ExoPlayer2 library (at least 2.10.4) since the replaced view is written above ExoPlayer's PlayerView
1) Include it to your gradle (it's hosted on jitpack.io so you've got to add it to your respositories):
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.vkay94:DoubleTapPlayerView:0.7.1'
}
2) Add the views inside your XML:
<FrameLayout
... >
<!-- Replace ExoPlayer's PlayerView -->
<com.github.vkay94.dtpv.DoubleTapPlayerView
android:id="#+id/doubletapplayerview"
app:player_layout_id="#layout/exo_simple_player_view"
app:use_controller="true"
...
/>
<!-- Other views e.g. ProgressBar etc -->
<!-- Add the overlay on top of PlayerView -->
<com.github.vkay94.dtpv.YouTubeDoubleTap
android:background="#color/dtp_overlay_dim"
android:id="#+id/youTubeDoubleTap"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
3) Set it up inside your activity:
// Link the PlayerView to the overlay to pass increment to the Player (seekTo)
// Important: set the (Simple)ExoPlayer to the PlayerView before this call
youTubeDoubleTap
.setPlayer(doubletapplayerview)
.setForwardRewindIncrementMs(5000)
// Set YouTube overlay to the PlayerView and double tapping enabled (false by default)
doubletapplayerview
.activateDoubleTap(true)
.setDoubleTapDelay(500)
.setDoubleTapListener(youTubeDoubleTap)
//.setDoubleTapListener(this) => handle event directly within´the activity
Link to the library on Github
Use FrameLayout instead of LinearLayout Like this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<FrameLayout
android:id="#+id/exo_rew"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#00000000"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground" />
<FrameLayout
android:id="#+id/exo_ffwd"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#00000000"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground" />
</LinearLayout>

How can I get a ZXing scanner in a section of a page?

I'm currently using this example source code to get a little bit familiar with ZXing. As of right now, the main screen looks like this:
When you press the 'Scan' button, it opens up the scanner in fullscreen and locks the orientation to landscape. Now instead of the scanner opening up fullscreen, I want it to open up only in a portion of the main screen. In other words, the scanner should only be inside the red box:
I've slightly altered the layout of the main screen, so that the fragment appears below the button:
<LinearLayout 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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".HomeActivity"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal">
<TextView
android:text="#string/hello_world"
android:id="#+id/tv_welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/activity_vertical_margin"/>
<TextView
android:text="#string/blog_url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_blog_url"
android:layout_marginBottom="#dimen/activity_vertical_margin"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btn_scan_now"
android:onClick="scanNow"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:id="#+id/btn_scan_now" />
<TextView
android:id="#+id/scan_format"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:gravity="center_horizontal"
android:layout_marginBottom="#dimen/activity_vertical_margin" />
<TextView
android:id="#+id/scan_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:gravity="center_horizontal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scan_fragment"
android:orientation="horizontal"></LinearLayout>
</LinearLayout>
In the first image below, you'll see what I'm trying to achieve in my own app. The second is what I have so far. The black section is where I want the scanner to go. Currently all that is, is a linear layout reserved for the fragment:
But this is where I've come to a stand still. I'm not sure how I can prevent the scanner from going fullscreen and landscape as well as locking it down to a specific area of a page. Can anyone provide some guidance on how to achieve this?
Thanks for any help in advance.

Create gallery with elements floating side by side or table cells

Friends I'm new to Android and I'm facing all those beginner's problems such as overload of information in the first steps of the learning proccess.
I want to develop an activity where its content resembles a picture gallery, with 2 pics per row. With HTML + CSS I would create divs with float:left and half of the parent element's width. Or maybe creating a table with two cells per row. Wouldnt do that in HTML for a photo gallery but I know it works.
I want to do this programmatically and Ive seen solutions with TableLayout and RelativeLayout. But i dont understand how to create a container such as DIV in HTML for the data (will be a title and an image) i want to place in the layout. And i dont understand how to make every two of them side by side.
How would you do that in terms of layout and programming?
I will update this thread with an image to a better understanding of my problem later.
Use below XML code as template to inflate in your activity and then add to ListView
In Main Activity inflate view by LayoutInflater:
LayoutInflater inflater = getActivity() .getLayoutInflater();
View view = inflater.inflate(R.layout.my_stats_layout, null);
Use Above view as item in ListView - Use this tutorial for custom ListView
http://androidexample.com/How_To_Create_A_Custom_Listview_-_Android_Example/index.php?view=article_discription&aid=67&aaid=92
XML Layout:
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/img1" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/img2" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Img1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Img2"
android:textColor="#000" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>

Categories