Android ScrollView overscroll indicator Issue - java

This is a strange issue I'm having with my Samsung GT-I9003L. I've a ScrollView containing a LinearLayout with different stuff inside (ImageView, Button, EditText, etc.) and it works perfectly when tested in the emulator, both in 2.3.3 and 4.2 versions.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp" >
<ImageView
android:id="#+id/image"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:contentDescription="#string/img_description"
android:src="#drawable/ic_launcher" />
<Button
android:id="#+id/btn_camera"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/add_new_btn_camera" />
<Button
android:id="#+id/btn_gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/add_new_btn_gallery" />
<EditText
android:id="#+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/add_new_name_hint"
android:inputType="text"
android:maxLength="80" />
[...]
</LinearLayout>
</ScrollView>
The thing is that when I test it on my phone, the overscroll indicators (the blue/orange glows) doesn't show at all. I've managed to get them working with this line:
ScrollView addNewScroll = (ScrollView)findViewById(R.id.scroll_view);
addNewScroll.setOverScrollMode(ScrollView.OVER_SCROLL_IF_CONTENT_SCROLLS);
But when I reach the top or the end, the glow just "appears", it doesn't animates or fades in.
Thanks in advance for your help!

We are having the exact same issue. Overscolling doesn't seem to work on Samsung Galaxy 2 (Touchwiz), but also on HTC One X phones (older HTC's seem to work).
Is suspect that they replaced the ScrollView implementation with their own, maybe for the stretchy scrollbars or something.

Related

Can't fully hide android material card background

Image how it looks
Can't fully hide android material card background. I have searched and watched all videos available but nothing has worked so far. I know I could just put something to fill the card but I want to know just in case.
The code:
<com.google.android.material.card.MaterialCardView
android:id="#+id/card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#40000000"
android:clickable="true"
app:cardCornerRadius="30dp"
android:layout_margin="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Planner"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="20sp"
android:fontFamily="#font/nova_bold"/>
<ImageView
android:layout_width="150dp"
android:layout_height="130dp"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:padding="1dp"
app:srcCompat="#drawable/ic_plan_vec" />
</com.google.android.material.card.MaterialCardView>
please use in your XML app:cardBackgroundColor="#color/yourColor"
or in your java code card.setCardBackgroundColor(YourColor); instead of the default setBackgroundColor()
UPDATE
for the opacity change android:backgroundTint="#40000000" by android:alpha="0.4"

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>

Localization and language difference issue in android

I'll try to make this short, So I created this Bluetooth Connection app and everything works perfect in my phone but i noticed an awful problem when I tested it on my friend's phone.
the problem is I'm using Linearlayout and two different buttons with image background on it for each row which stands aside each other, the circle standing on the left side of the rectangle which is correct and that's how it works on my phone, but when it comes to my friend's phone which has a different Language ( Language and Input in android settings ) the circle is on the right side of the rectangle.
Please note that i already know the fact that this can be fixed if he change the phone language to English just like mine, But i'm looking for a solution which wouldn't cause any trouble for all type of costumers in my country with two different phone languages.
Well, How am i supposed to fix this ?
How it looks on my phone
How it looks on my friend's phone
<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:orientation="vertical"
android:padding="#dimen/activity_vertical_margin">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="200dp">
<Button
android:layout_width="75dp"
android:layout_height="70dp"
android:id="#+id/circle1"
android:background="#drawable/redcircle />
<Button
android:layout_width="75dp"
android:layout_height="70dp"
android:id="#+id/greenCircle"
android:background="#drawable/greencircle"
android:alpha="0"/>
</FrameLayout>
<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="5dp"
android:id="#+id/rect1"
android:text="Bluetooth Turn On / Off"
android:textStyle="italic"
android:textColor="#fdfdfd"
android:background="#drawable/rects"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_weight="1.4"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="150dp"
android:layout_height="70dp"
android:id="#+id/circle2"
android:background="#drawable/gomb"
android:layout_weight="1" />
<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="#+id/rect2"
android:textStyle="italic"
android:text="View paired Devices"
android:textColor="#fdfdfd"
android:enabled="false"
android:background="#drawable/rects"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.9">
<Button
android:layout_width="150dp"
android:layout_height="70dp"
android:id="#+id/circle3"
android:background="#drawable/gomb"
android:layout_weight="1" />
<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="#+id/rect3"
android:textStyle="italic"
android:textColor="#fdfdfd"
android:enabled="false"
android:text="Scan for new Devices"
android:background="#drawable/rects"
android:layout_weight="1" />
</LinearLayout>
Looks like your friend's phone is in a right-to-left language, and your app "supports" right-to-left. While supporting RTL is an admirable goal, sometimes it's not feasible.
You have a few different options here. The fastest/easiest for you is to disable RTL support from your app. Add this attr to the <application> tag in your AndroidManifest.xml:
android:supportsRtl="false"
Or, you could try to actually provide the necessary support for RTL within your app. In this case, that probably means specifying an alternative drawable for your button background. If you currently have these:
res/drawable-mdpi/background.png
res/drawable-xhdpi/background.png
res/drawable-xxhdpi/background.png
You'd need to add these:
res/drawable-ldrtl-mdpi/background.png
res/drawable-ldrtl-xhdpi/background.png
res/drawable-ldrtl-xxhdpi/background.png
And you'd put the curvature on the right side of the button instead of the left.

how to differentiate two "views" from overlapping each other

i am beginner to android programming and trying to build a simple app program.
whenever i try to make more than one views they stack on each other.
I am trying to make a text field and a button, but when i run it, the text field and button overlap each other however, i want them to be separated by some distance.
i am using the following code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="com.example.new1.MainActivity" >
<EditText android:id="#+id/edit_message"
android:layout_weight= "1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
</RelativeLayout>
i am checking this code on Samsung Galaxy S2.
does anybody knows the solution to this problem and can guide me where i am doing it wrong.
Either use LinearLayout so that elements stack horizontally or vertically, or use attributes such as android:layout_toRightOf="#id/edit_message" to control placement within a RelativeLayout.
Find out more about LinearLayout here: http://developer.android.com/guide/topics/ui/layout/linear.html and RelativeLayout here: http://developer.android.com/guide/topics/ui/layout/relative.html
RelativeLayout positions views relative to each other. So if you do not specify the relationship between view, all the views will be put one above the other. You can either use LinearLayout with orientation attribute or define relationship between views. Following can be your working code
<?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" >
<EditText
android:id="#+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:hint="#string/edit_message"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/edit_message"
android:text="#string/button_send" />
</RelativeLayout>
Here android:layout_toRightOf="#id/edit_message" lets your button to be positioned to right of your edittext
Depending on what you want, a horizontal layout or vertical, you need a fitting layout xml.
You use relativeLayout, where you have to specify the parents to layout like:
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
If your beginner better take a look at a linear layout in vertical or horizontal mode.
You dont have to specify this then.
Like this:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100"
>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/bResults"
android:text="Try Command"
android:layout_weight="20" />
<ToggleButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tbPassword"
android:layout_weight="80"
android:checked="true"
/>
</LinearLayout>
This will put your two buttons nexto each other

toRightOf not working as expected in an android layout

Here is my layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/outerBox"
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<GridLayout
android:id="#+id/checksHere"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:columnCount="5"
android:columnWidth="100dp" />
<GridLayout
android:id="#+id/textHere"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/checksHere"
android:columnCount="4" />
<Button
android:id="#+id/submitButton"
android:layout_width="185dip"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/outerBox"
android:layout_below="#id/textHere"
android:layout_margin="3dip"
android:onClick="submit"
android:text="#string/submit" />
<Button
android:id="#+id/cancelButton"
android:layout_width="185dip"
android:layout_height="wrap_content"
android:layout_below="#id/textHere"
android:layout_margin="3dip"
android:layout_toRightOf="#id/submitButton"
android:onClick="next"
android:text="#string/cancel" />
<Button
android:id="#+id/backButton"
android:layout_width="185dip"
android:layout_height="wrap_content"
android:layout_below="#id/textHere"
android:layout_margin="3dip"
android:layout_toRightOf="#id/cancelButton"
android:onClick="next"
android:text="test" />
</RelativeLayout>
I have a relative layout. The layout has two grid layouts at the top, which can be populated in my java code with text or checks. They can be blank. Then I have three buttons. The first two buttons display on the screen just fine. The third button just sits on top of the first button:
I changed the third button (backButton) to be toRightOf submitButton just to see what would happen. It goes on top of the cancelButton, as expected. I feel like I'm missing a simple fundamental, but I have not been able to figure it out.
Well this doesn't necessarily fix the problem with RelativeLayout, but you could always group the three buttons together in a single LinearLayout. This should prevent the buttons from overlapping.
I am not sure but when testing in eclipse changing all the android:layout_width="185dip" to android:layout_width="wrap_content" for buttons worked for me.

Categories