Android remove cardview padding - android-cardview

From everything I have read, I should have cardview:cardPreventCornerOverlap="false" in my XML file to prevent padding between each cardview.
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:id="#+id/card_view"
cardview:cardPreventCornerOverlap="false"
cardview:cardUseCompatPadding="false"
cardview:cardBackgroundColor="#android:color/holo_green_light"
android:layout_width="match_parent"
android:layout_height="100dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image"
android:layout_width="120dp"
android:layout_height="100dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:layout_alignTop="#id/image"
android:layout_toEndOf="#id/image"
android:layout_toRightOf="#id/image"/>
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxLines="2"
android:ellipsize="end"
android:layout_alignStart="#id/name"
android:layout_alignLeft="#id/name"
android:layout_below="#id/name" />
</RelativeLayout>
Yet, on my LG phone running 4.4.2, I am seeing white space i.e. padding between the cards. I deliberately set the background to light green.
Here is the screenshot.
enter image description here

Related

How to Disable Swipe Refresh when Bootstrap Modal Appears in Android WebView?

I am building an Android WebView app and website which I load in WebView contain Bootstrap Modal ,it appears as Login/SignUp popup or Choose Image popup.
But problem is that when Modal appears Swipe refresh is working and i am not able to scroll up as swipe refresh automatically refresh the page, So i want to disable swipe refresh only when modal opens.
In Chrome App ,swipe refresh automatically disables when Modal opens or appears so i want setting just as chrome android app.
Thanks in Advance
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"
android:background="#color/black"
android:id="#+id/relative"
tools:context=".MainActivity">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/swipeRefreshLayout"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:ignore="WebViewLayout">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="8dp"
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_marginTop="-2dp"
android:progress="20"
android:visibility="gone"
android:indeterminate="true"
android:indeterminateTintMode="src_atop"
android:indeterminateTint="#color/white" />
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/myWebView"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:nestedScrollingEnabled="true"
android:isScrollContainer="true"
tools:ignore="ObsoleteLayoutParam,RtlHardcoded" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black"
android:id="#+id/relativeLayout">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No Internet Connetion, Please Connect To Internet And Try Again. "
android:textSize="30dp"
android:textColor="#color/white"
android:layout_centerHorizontal="true"
android:textAlignment="center"
android:layout_marginTop="40dp"
android:id="#+id/txtNoConeection"
android:layout_marginRight="23dp"
android:layout_marginLeft="25dp"
android:gravity="center_horizontal" />
<Button
android:layout_width="140dp"
android:layout_height="65dp"
android:text="Retry"
android:backgroundTint="#color/white"
android:textColor="#620839"
android:layout_below="#+id/txtNoConeection"
android:layout_centerHorizontal="true"
android:layout_marginTop="400dp"
android:textSize="20dp"
android:id="#+id/btnNoConnection"/>
</RelativeLayout>
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</RelativeLayout>
In onCreate
swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setColorSchemeColors(Color.rgb(0,72,85), Color.rgb(255,216,96) , Color.rgb(93,7,53) );
swipeRefreshLayout.setOnRefreshListener(() -> {
webView.reload();
if (null != swipeRefreshLayout){
swipeRefreshLayout.setRefreshing(false);
}
});
//Solved WebView SwipeUp Problem
swipeRefreshLayout.getViewTreeObserver().addOnScrollChangedListener(() -> swipeRefreshLayout.setEnabled(webView.getScrollY() == 0));
It's pretty old but since it shows up on google searches, might help some people...
I solved it with a weird method. Just added some js to my website. not using bootstrap but is there any reason it wouldn't work?
when I'm opening the div:
document.body.style.overflowY = "hidden";
document.body.style.minHeight = "calc(100vh + 1px)";
window.scrollBy(0, 1);
and when I'm closing it:
document.body.style.overflowY = "scroll";
document.body.style.minHeight = "0px";
window.scrollBy(0, -1);
if you have found a better solution i would like to hear about it as well...
i really don't understand why it's not fixed yet. chrome handles it perfectly but webview is still like this...
first i tried using
document.body.style.overscrollBehavior = "none";
but it has no effect in webview...

Horizontally aligning two TextViews in Constraintlayout

Helllo!
I am currently learning the basics os JAVA and I can't quite figure a little thing out...
What I want to do: Horizontally align two TextViews in a CardView, while keeping them contrained to eachother
What I have tried:
Constraining them separately, this creates space between those two TextViews which I do not want.
Also I have played around with Chains, but couldn't quite get it to work (doing it wrong probably).
Lastly I tried searching this forum but could only find very big problems where mine did not fit into (relative layouts and others)
Image of the Android Editor: https://imgur.com/ICLPv8v
The pink circle is where Im having trouble with (too much space in between)
This is the code so far I've come up with :-)
FYI: I'm following the Android Basics: User Interface and it's been fun, this just seemed a bit too advanced for them, but I'm eager to learn!
<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">
<androidx.cardview.widget.CardView
android:id="#+id/materialcard"
android:layout_width="200dp"
android:layout_height="200dp"
android:backgroundTint="#color/Gray200"
app:cardCornerRadius="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/Hi"
style="#style/Headline1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="2dp"
android:text="Hi"
android:textColor="#color/Gray900"
android:textStyle="bold"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="#+id/materialcard"
app:layout_constraintTop_toTopOf="#+id/materialcard" />
<TextView
android:id="#+id/ExclamationMark"
style="#style/Headline_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="2dp"
android:text="!"
android:textAlignment="center"
android:textColor="#color/colorAccent"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="#+id/materialcard"
app:layout_constraintLeft_toLeftOf="#+id/materialcard"
app:layout_constraintStart_toEndOf="#+id/Hi"
app:layout_constraintTop_toTopOf="#+id/materialcard" />
</androidx.constraintlayout.widget.ConstraintLayout>```
[1]: https://i.stack.imgur.com/Fd8Jf.png
You can use this layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
android:background="#color/cardview_dark_background">
<androidx.cardview.widget.CardView
android:id="#+id/materialcard"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintWidth_percent="0.7"
app:layout_constraintHeight_percent="0.4"
app:cardCornerRadius="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/Hi"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#color/colorPrimary"
app:layout_constraintWidth_percent="0.34"
app:layout_constraintHeight_percent="0.4"
android:elevation="2dp"
android:text="Hi"
android:textStyle="bold"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="#+id/materialcard"
app:layout_constraintTop_toTopOf="#+id/materialcard" />
<TextView
android:id="#+id/ExclamationMark"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#color/colorAccent"
app:layout_constraintWidth_percent="0.34"
app:layout_constraintHeight_percent="0.4"
android:elevation="2dp"
android:text="!"
android:textAlignment="center"
android:textColor="#color/colorAccent"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="#+id/materialcard"
app:layout_constraintLeft_toLeftOf="#+id/materialcard"
app:layout_constraintStart_toEndOf="#+id/Hi"
app:layout_constraintTop_toTopOf="#+id/materialcard" />
</androidx.constraintlayout.widget.ConstraintLayout>
The important thing are those attributes:
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintWidth_percent="0.7"
app:layout_constraintHeight_percent="0.4"
By doing that, now your cardView will be be exactly 70% of the screen with and 40% of the screen hegiht.
And now if you look at the layout I have done that for the other views, allowing myself to control the space inside the cardView.

ConstraintLayout 1.1.0 views cannot reference each other on the same edge?

The following code used to work fine in 1.0.2, but does not work in 1.1.0 stable - literally removes the effect of every other constraint in all views in the layout. Is there a reason or is it just a quirk? Took a while to hunt it down.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:app1="http://schemas.android.com/apk/res-auto">
<TextView
android:id="#+id/viewOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="#+id/viewTwo" <-- culprit
tools:text="View one"/>
<TextView
android:id="#+id/viewTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app1:layout_constraintTop_toBottomOf="#+id/viewOne" <-- culprit
tools:text="View two"/>
</android.support.constraint.ConstraintLayout>
Removing one of the culprit constraints brings everything back to normal in 1.1.0.
Add app:layout_constraintTop_toTopOf="parent" to viewOne and it will work again. You can also remove app:layout_constraintBottom_toTopOf="#+id/viewTwo" and nothing will change since it is not needed.
Although the two views are vertically constrained, they are constrained to one another and nothing ties them to the container. The group will slide to the top by default if not otherwise constrained. It look like both will slide to the top in 1.1.0 and line up one below the other in 1.0.2. This may be just a side effect of how the views are defined.
In any case, the XML is not well-formed and the views should all be constrained either directly or indirectly to the containing ConstraintLayout. Make the changes above and all will be well.
Just remove
app:layout_constraintBottom_toTopOf="#+id/viewTwo"
from the above xml code and you are good to go.
Below given is the code that works perfectly well.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:app1="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/viewOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="View one" />
<TextView
android:id="#+id/viewTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app1:layout_constraintTop_toBottomOf="#+id/viewOne"
tools:text="View two" />
</android.support.constraint.ConstraintLayout>
So in your case only
app:layout_constraintBottom_toTopOf="#+id/viewTwo" this is the culprit.

Android ImageButton interaction

I wish to create the same activity like in google fit
And I created an activity with android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<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:background="#ddd"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="12dp"
android:background="#null"
android:onClick="onPreferencesClick"
android:src="#drawable/ic_more_vert_grey600_24dp" />
But when I click on three dots button it doesn't have any push effect in ui, but onPreferencesClick works fine.
How to create pushable ImageButton?
The easiest way would be to create a custom selector, for example like this (drawable xml):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#33000000"/>
<item android:drawable="#android:color/transparent"/>
</selector>
and apply it to the background of ImageButton

How to change subtitle color in listVIew

I have a listView. Each list item consists of a title and a subtitle under title. I want to change the color of the subtitle. Please help me to change.
This is the layout you can use to make a different color textview for your subtitle:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#999999">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
Color Change on this text view
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Small Text"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
After this you can make your own adapter and inflate your row and you will get the different color on your txtview in the listview you mentioned.
Hope this helps.