UI bug android - screen not matched on top edge - android

I'm working on this app and I have implemented a photo slider through ViewPager. There is an imported circle page slider indicator, a project on github. It looks like this: (Sorry for the blured text, I'm not able to share the content until release. The app will be free)
My problem is that thin blue line on the top of the screen. Blue color comes from the background and it is set in the root layout of the activity. No matter what I do to the any of the layouts (changing margins or padding to negative values) this line remains there.
So I figured that it has to do with the chosen theme for the screen. Theme is set to a custom theme which has Theme.NoTitleBar as it's parent. The code is below:
This is the style file. Taken from http://viewpagerindicator.com/ by Jake Wharton.
<style name="Theme.PageIndicatorDefaults" parent="android:Theme.NoTitleBar">
<!--<item name="vpiIconPageIndicatorStyle">#style/Widget.IconPageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>-->
<item name="vpiCirclePageIndicatorStyle">#style/Widget.CirclePageIndicator</item>
</style>
This is my activity layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/accountRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradientbg"
android:orientation="vertical"
android:gravity="bottom">
<RelativeLayout
android:id="#+id/titleBar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:visibility="visible"
>
<android.support.v4.view.ViewPager
android:id="#+id/viewPagerSlider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never"
/>
<io.colomb.android.colombio.customviews.CirclePageIndicator
android:id="#+id/slideIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_centerHorizontal="true"
android:layout_alignBottom="#id/viewPagerSlider"
android:layout_marginBottom="20dp"
android:paddingRight="5dp"
android:paddingLeft="5dp"
/>
</RelativeLayout>
<ImageView
android:id="#+id/ivSoftboardLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/logosoftboard"
android:layout_gravity="center_horizontal"
android:contentDescription="#string/app_name"
android:layout_marginTop="10dp"
android:visibility="gone"
android:layout_marginBottom="15dp"
/>
<LinearLayout
android:id="#+id/InputFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="0.001"
android:layout_marginTop="-15dp"
>
</LinearLayout>
Any thoughts are appreciated.

OK solved. The thing that was bothering the adapter was the line gravity="bottom"in the root element. Also the pictures needed to be cropped more

Related

How to reduce material.switchmaterial.SwitchMaterial end margin in android?

I've used "com.google.android.material.switchmaterial.SwitchMaterial" in that left margin having some space. How to reduce that?
I've need align straight of the everyone text. I'm not add end margin or padding of the switch, Parent layout margin only I've set. Below my XML code and styles. Please provide your suggestion to reduce that margin, Thanks.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
<RelativeLayout
android:id="#+id/who_can"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp">
<com.google.android.material.textview.MaterialTextView
style="#style/TextBlackRegular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_toStartOf="#+id/video_view_result"
android:singleLine="true"
android:text="#string/who_can_view"
android:textSize="#dimen/text_small"
android:visibility="visible" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/video_view_result"
style="#style/TextBlackRegular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:singleLine="true"
android:text="Everyone"
android:textSize="#dimen/text_small" />
</RelativeLayout>
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="#+id/save_switch"
style="#style/SwitchButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/who_can"
android:checked="true"
android:text="#string/save_gallery"
android:textSize="#dimen/text_small"
app:trackTint="#color/colorSecondaryText" />
</RelativeLayout>
<style name="SwitchButtonStyle" parent="Widget.MaterialComponents.CompoundButton.Switch">
<item name="thumbTint">#drawable/switch_selector</item>
<item name="android:fontFamily">#font/font_regular</item>
<item name="android:textColor">#color/colorBlack</item>
</style>
In your relativeLayout/topRelativeLayout, You added margin. Which means you want to margin from every side. That's why It's happening
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
remove the android:layout_margin="10dp". Add margin_top, margin_right what you wanna do.
You should give wrap content for switch width , or make it inside a new Relative layout
if your end margin is showing after removing from
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
then
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="#+id/save_switch"
style="#style/SwitchButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/who_can"
android:checked="true"
android:text="#string/save_gallery"
android:textSize="#dimen/text_small"
app:trackTint="#color/colorSecondaryText" />
change in SwitchButtonStyle it gives you some default value we are happy if you share whole file
you can see that default drawables (thumb and track) from a theme have this paddings
so the way is try to use your custom drawables (but this may affect their appearance)
app:track="#drawable/track"
android:thumb="#drawable/thumb"

Android ImageButton not enforcing transparency in RelativeLayout

I am trying to place two image buttons and some text on a single line. Here is the XML for the layout:
<?xml version="1.0" encoding="utf-8"?>
<mycompany xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="28dp"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<ImageButton
android:id="#+id/sectionDelete"
android:layout_width="35dp"
android:layout_height="28dp"
android:layout_alignParentLeft="true"
android:src="#drawable/button_delete" />
<TextView
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/sectionDelete"
android:text="test"
android:textAllCaps="true"
android:textColor="#color/navigation_bar"
android:textSize="16sp"
android:textStyle="bold" />
<ImageButton
android:id="#+id/sectionAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/button_add" />
</RelativeLayout>
<View
android:id="#+id/line"
android:layout_marginTop="8dp"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#android:color/darker_gray" />
</LinearLayout>
</mycompany>
The selector XML for each of the buttons in drawable:
button_delete.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/delete_button_pressed"
android:state_pressed="true" />
<item android:drawable="#drawable/delete_button"
android:state_focused="true" />
<item android:drawable="#drawable/delete_button" />
</selector>
button_add.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/button_add_pressed"
android:state_pressed="true" />
<item android:drawable="#drawable/button_add_normal"
android:state_focused="true" />
<item android:drawable="#drawable/button_add_normal" />
</selector>
In the builder all looks well:
But in the application the gray background is lost and the edges of the image (which are transparent) are shown, but only for the first image:
Strangely, the first image button is not recognizing the transparent background of the image. Additionally I needed to mess with the width and height of the RelativeLayout and the first ImageButton to even get it close to the right size. With the 2nd I did not have to do anything. There is nothing special with the first image.
Here are the images from the directory:
One last issue - How do you make the text wrap before the 2nd image if it is too long for the space? Right now it writes under the 2nd image before wrapping:
Here are all the delete images. Seem to have transparent backgrounds, but I am far from a Gimp expert. Also not sure if StackOverflow keeps the original..
Update
I have verified the images are transparent. The image still has the white background. I have also updated the XML to look like this:
<?xml version="1.0" encoding="utf-8"?>
<mycompany xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<ImageButton
android:id="#+id/sectionDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#drawable/button_delete" />
<TextView
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/sectionDelete"
android:layout_toEndOf="#+id/sectionDelete"
android:layout_toLeftOf="#+id/sectionAdd"
android:text="test"
android:textAllCaps="true"
android:textColor="#color/navigation_bar"
android:textSize="16sp"
android:textStyle="bold" />
<ImageButton
android:id="#+id/sectionAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#drawable/button_add" />
</RelativeLayout>
<View
android:id="#+id/line"
android:layout_marginTop="8dp"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#android:color/darker_gray" />
</LinearLayout>
</mycompany>
You should use:
<ImageButton
android:id="#+id/sectionDelete"
android:layout_width="35dp"
android:layout_height="28dp"
android:layout_alignParentLeft="true"
android:src="#drawable/button_delete"
android:background="#android:color/transparent"/>
Use "#null" like background on ImageButton:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/bkash"
android:id="#+id/bid1"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#null" />
You haven't included the actual PNG file you are using as an icon for your delete button (screenshot from Windows's Explorer showing this file on your disk isn't quite enough), but I am almost sure that this file lacks an alpha channel. Instead, there is a white color on every pixel you'd like to be set with zero alpha channel value.
Opening your graphic in some image editor and changing these white pixels to transparent will solve your problem, but as for the reason why your layout "looks different" in builder than on your device, it's because there is a default theme applied by the system to every app, you can read more about it here: https://developer.android.com/guide/topics/ui/look-and-feel/themes.html
This default, OS and device specific set of values determines things that aren't determined by app's authors.
In the case of your device, its OS determined app's background color to be gray, which wasn't the case with your builder. Your builder chose the background to be white. Your delete button's graphic never was transparent, but on the white background of your builder it looked like it was.
To make it look like on builder, you need to specifically apply the background by yourself to the root of your view. In this case, it's a LinearLayout which should look like this:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff">
1) #DimDim had the right solution, if it didn't work, the delete button may have white background in the image, cross check with a png viewer.
2) To prevent overflow of text, try this
<TextView
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/sectionDelete"
android:layout_toLeftOf="#+id/sectionAdd"
android:text="test"
android:textAllCaps="true"
android:textColor="#color/navigation_bar"
android:textSize="16sp"
android:textStyle="bold" />
And put the sectionAdd Image button above this textview in the XML as this textview needs reference to the sectionAdd.

Why is the framelayout not drawing z index correctly?

Here is the full XML android layout file code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content" >
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="New Button"
android:textAllCaps="false"
android:textSize="15pt"
android:id="#+id/element_button"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/element_number"
android:layout_gravity="top|left" />
</FrameLayout>
It produces this in the android Studio preview window as well as on the device:
Am I losing it? What gives? As you can see, the "New Text" text view is BEHIND the button. When in every code sample I found on stackoverflow, and in simple programming logic, the button gets drawn FIRST, THEN the TextView, therefore, textview is on top of button. But its not. This happens with the RelativeLayout as well.
You're not crazy it's the theme in your Styles that is doing it:
Will make the crazy ordering:
<style name="AppTheme" parent="android:Theme.AppCompat">
Will restore your sanity:
<style name="AppTheme" parent="android:Theme.Holo">
WHY it's doing it ... maybe a bug, maybe a change, sorry I'm not sure
You can play around with the themes here to prove it:
vs
Try use elevation in your xml layout
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/element_number"
android:layout_gravity="top|left"
android:elevation="2dp" />
or set by code
ViewCompat.setElevation(this, 2);

How to set transparent background during translate animation android?

I've the following problem. I've a TableLayout and two TableRows. Both TableRows contain two ImageButton. When a button is clicked I want to fade out other three buttons and translate the clicked button at the center of the screen. When it is translated the top or bottom half disappeared like it's hidden by the other table row. I've tried to set transparent background of table rows, to set alpha=0, to change layout and also I've tried to use ScaleAnimation, but the problem doesn't disappear. How can i show the disappeared half? I post also the layout code and a link to the screen with the problem.
http://it.tinypic.com/r/1zejhir/5
`
<RelativeLayout
android:id="#+id/l34"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_alignParentTop="true">
<ImageButton
android:id="#+id/four"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top|right"
android:src="#drawable/unor"
android:alpha="0"
android:onClick="translate"
android:layout_alignParentLeft="true" />
<ImageButton
android:id="#+id/three"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top|left"
android:src="#drawable/unor"
android:alpha="0"
android:onClick="translate"
android:layout_alignParentRight="true" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/l12"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true">
<ImageButton
android:id="#+id/one"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top|right"
android:src="#drawable/unor"
android:alpha="0"
android:onClick="translate"
android:layout_alignParentLeft="true" />
<ImageButton
android:id="#+id/two"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top|left"
android:src="#drawable/unor"
android:alpha="0"
android:onClick="translate"
android:layout_alignParentRight="true" />
</RelativeLayout>
</RelativeLayout>
`
The problem is that you want to use "space" from other viewgroups, your view is bound to the hosting viewgroup (eg tablerow). It doesn't have anything to do with the transparent background. The solution would be to have one viewgroup holding all your icons. For example use a RelativeLayout.
make transparent
in java code-> imagebtn.setBackgroundColor(Color.TRANSPARENT);
xml-> android:background="#android:color/transparent"
create modify the styles.xml file resource in values folder, with following code
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
in manifest.xml file add the below step to which activity make you as transparent.
android:theme="#style/Theme.Transparent"

Android: how to make two TextViews placed in different lines if there is not enough space in one line

I'm trying to organize two TextViews to behave like that:
So, if there is enough space for both TextViews in line, android should place them in line.
If there is not enough space, the second TextView must be placed on the next line with right alignment.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/takeoffCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/flightItem" />
<TextView
android:id="#+id/landingCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/flightItem" />
</LinearLayout>
<style name="flightItem" parent="#android:style/TextAppearance">
<item name="android:textSize">14dip</item>
<item name="android:textColor">#color/flightItemFont</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:textStyle">bold</item>
</style>
To accomplish what you are looking for you could change you're layout to a RelativeLayout and add android:layout_alignParentLeft="true" to your TextViews, however, this doesn't set these TextViews to act dynamically. Meaning if they can fit side-by-side then they should be in-line but the bottom TextView will still align to the right.
I don't think what you are looking for is technically possible. However this may be a good alternative:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/takeoffCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
style="#style/flightItem" />
<TextView
android:id="#+id/landingCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
style="#style/flightItem" />
</RelativeLayout>

Categories

Resources