I have a radio button with a selector background and an animation.
All of them work correctly. But there is a problem with the alignment of the circle in the radio button. When I try to set the margin to it, It changes with the background drawable. Is there any way to move the radio button's circle only?
Also please help me in the case of checkboxes.
rbtn_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<shape>
<solid android:color="#8effffff" />
</shape>
</item>
<item android:state_checked="false">
<shape android:shape="rectangle">
<solid android:color="#51ffffff" />
</shape>
</item>
activity_radio.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:gravity="center"
android:layout_height="match_parent"
android:background="#drawable/back1"
tools:context="com.wiinnova.custom_views.RadioActivity">
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<android.support.v7.widget.AppCompatRadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/rbtn_selector"
android:layoutDirection="rtl"
android:paddingLeft="10dp"
android:text="apple"/>
</RadioGroup>
Try by setting background android:background="#drawable/rbtn_selector" to RadioGroup instead of android.support.v7.widget.AppCompatRadioButton
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical"
android:gravity="center"
android:layout_height="match_parent"
android:background="#drawable/back1"
tools:context="com.wiinnova.custom_views.RadioActivity">
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#drawable/rbtn_selector"
android:orientation="vertical" >
<android.support.v7.widget.AppCompatRadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutDirection="rtl"
android:paddingLeft="10dp"
android:layout_margin="10dp"
android:text="apple"/>
</RadioGroup>
</LinearLayout>
I just used a custom image for the radio button drawable with some transparent padding. And replaced that selected drawable at the same position as for click effects. And created a selector to change the drawable while checking the radio button.
Thanks Mohit
Related
I want to add a background behind the button. I want to create an opaque shape from white color for this background.. I did this with a gradient, but I couldn't. I want to create a soft shape.. I want a white shape like in the picture
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="270"
android:dither="false"
android:endColor="#FFFFFF"
android:startColor="#CCFFFFFF" />
<corners android:radius="5dp" />
</shape>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#drawable/drop_shadow" // here
android:paddingTop="16dp">
<TextView
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/green"
android:gravity="center"
android:text="#string/next"
android:textColor="#color/white"
android:textSize="22sp"
android:textStyle="bold" />
</RelativeLayout>
You should use a FrameLayout as root layout, and use an ImageView anchored to the bottom of the screen:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/id_framelayout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".YourActivity">
<TextView
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/green"
android:gravity="center"
android:text="#string/next"
android:textColor="#color/white"
android:textSize="22sp"
android:textStyle="bold"
/>
<LinearLayout
android:orientation="vertical"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatImageView
android:src="#drawable/shadow"
android:layout_width="match_parent"
android:layout_height="200dp"
/>
<FrameLayout
android:background="#color/white"
android:layout_width="match_parent"
android:layout_height="200dp">
< IF YOU WANT, YOU CAN INSERT HERE YOUR BUTTON >
</FrameLayout>
</LinearLayout>
</FrameLayout>
The shadow should be defined on res/drawable/shadow.xml as follows:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="-90"
android:endColor="#FFFFFF"
android:centerColor="#88FFFFFF"
android:startColor="#android:color/transparent"
android:type="linear">
</gradient>
</shape>
How do you make an animation that revolves around the text. The text must remain constant, it will just turn around the edge. There is an object rotating in the direction of the arrow
Your requirement is clockwise animation for Textview.
[1]. Design XML as below code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout
android:layout_marginTop="40dp"
android:id="#+id/relative"
android:padding="50dp"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="40dp"
android:text="Hello Rotate Me!"
android:gravity="center"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="120dp"
android:layout_margin="10dp"
android:layout_height="wrap_content"
android:id="#+id/tvRotation"
android:layout_centerInParent="true"
android:padding="10dp"
android:background="#drawable/back_txt"/>
</RelativeLayout>
<Button
android:layout_marginTop="20dp"
android:id="#+id/btnStart"
android:layout_width="80dp"
android:background="#000000"
android:layout_height="50dp"
android:text="start"
android:textColor="#ffffff"/>
</LinearLayout>
[2]. Create anim named folder in res directory. In anim create file named clockwise.xml and put below code into it.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="#android:anim/cycle_interpolator">
<rotate android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:duration="1000" />
</set>
[3]. put below code into your activity
TextView edtRotation=findViewById(R.id.YOUR_TEXTVIEW_ID);
Animation aniRotate = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.clockwise);
edtRotation.startAnimation(aniRotate);
[4]. Background Drawable as per you want but my drawable file code is back_txt
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:color="#0000ff" android:width="2dp"/>
</shape>
I am trying to draw a title bar on the top of a card view.
This is what I am getting (Also why is the text "Test Title Goes Here" not being drawn?
but I am looking for this
This is the xml I am using to get this
<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v7.widget.CardView
android:id="#+id/card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:innerRadius="0dp"
android:shape="ring"
android:thicknessRatio="1.9"
app:cardCornerRadius="40dp"
app:contentPadding="13dp"
tools:layout_editor_absoluteY="35dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/header_when"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#D3D3D3"
android:textColor="#000000"
android:textStyle="bold"
android:padding="8dp"
tools:text="Test Title Goes Here" />
<com.google.android.flexbox.FlexboxLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:alignContent="stretch"
app:alignItems="stretch"
app:flexDirection="row"
app:flexWrap="wrap"
app:justifyContent="flex_start">
</com.google.android.flexbox.FlexboxLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
Any help is greatly appreciated
Passing a xml for your textview should help you. Add the xml as background for the textview in your main xml layout. In the custom textview xml do something like this:-
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffffff"/>
<stroke android:width="3dp"
android:color="#ff000000" />
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp" />
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp" />
</shape>
I hope this helps.
I have an imageview and a cardview elevated on top of it. The cardview contains multiple views inside it.
I want to set a background color to cardview such that its startcolor should make the initial part of the imageview behind it to be visible at a transparency rate of 30% and the cardview should become darker and darker and black at the end.
This is what I have tried so far:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#80000000"
android:endColor="#FF000000"
android:angle="270"
android:dither="true"
/>
</shape>
This doesn't make my imageview visible.I have explored many SOF posts but wasn't able to reproduce what I want!
Any inputs are welcome and would be very helpful!!
Use this XML code
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#21293B"
android:centerColor="#21293B00"
android:endColor="#00000000"
android:angle="90"/>
</shape>
put it as a background to a View, put that View above your ImageView
<RelativeLayout
android:id="#+id/player_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/shasha_poster"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:minHeight="500dp"
android:scaleType="centerCrop"
android:src="#drawable/placeholder"
android:visibility="visible" />
<View
android:id="#+id/gradient"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background_with_shadow2" />
</RelativeLayout>
You can do something like this
// this is your back image
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/xxxxx"
...
/>
// your cardview over the image
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="100dp"
app:cardBackgroundColor="#00000000" // make cardview transparent
...
>
// an image to make the new drawable background
<ImageView
android:background="#drawable/gradient" // the xml with your gradient
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
/>
</android.support.v7.widget.CardView>
I think this is what you looking for, I test this and work as you expected.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/your_image" />
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
card_view:cardBackgroundColor="#color/transparent"
card_view:cardCornerRadius="5dp"
card_view:cardElevation="0dp"
card_view:cardMaxElevation="0dp"
card_view:cardPreventCornerOverlap="false"
card_view:cardUseCompatPadding="true"
card_view:contentPaddingTop="2dp">
<RelativeLayout
android:id="#+id/list_container_bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/your_gradient"
android:gravity="center"
android:orientation="vertical">
<!--Add your cardview contents-->
</RelativeLayout>
</android.support.v7.widget.CardView>
</FrameLayout>
This is the gradient background file your_gradient.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#80000000"
android:endColor="#FF000000"
android:angle="270"
android:dither="true"
/>
</shape>
I want to set a TextView right on the upper edge of a LinearLayout in Android.
I'm trying to achieve something like this
But I'm getting this:
What I have done so far:
content_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:id="#+id/tableLayout"
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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="tries.auro.tryapp.MainActivity"
tools:showIn="#layout/activity_main"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:scrollbars="vertical"
android:background="#drawable/bg"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="33dp"
android:id="#+id/linearLayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="BLAH BLAH!!"
android:id="#+id/textView"
android:layout_marginLeft="33dp"
android:layout_marginStart="33dp"
android:layout_alignTop="#+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</LinearLayout>
</RelativeLayout>
And I made a background, called bg.xml for my LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle">
<solid android:color="#000000"/>
</shape>
</item>
<item
android:left="2dp"
android:right="2dp"
android:bottom="2dp"
android:top="2dp">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF"/>
</shape>
</item>
</layer-list>
I am quite new to Android & I find this quite challenging. So I was wondering if anyone knew how I could achieve this
Thank you for your time!!
Please check this one
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:background="#drawable/bg" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="40dp"
android:layout_marginTop="15dp"
android:background="#drawable/bg"
android:text=";dslf;ldfsgk;" />
I would try to do something like this (Use the code of floating action button but change the floating action button with a TextView):
<android.support.design.widget.CoordinatorLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout>
<LinearLayout
android:id="#+id/viewA"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.15">
</LinearLayout>
<LinearLayout
android:id="#+id/viewB"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.85" >
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_horizontal_margin"
app:layout_anchor="#id/viewA"
app:layout_anchorGravity="left|bottom"/>
</android.support.design.widget.CoordinatorLayout>