How to have an expandable CardView? - java

I'm trying to develop an app right now that uses CardViews, and I'd like to have them be expandable; that is to say that upon someone pressing the CardView, it should expand to show more details. How would I go about doing this?
Here's a visual explanation of what i'm trying to do; when I press the highlighted CardView, I want it to expand to show more information, and be able to contract upon another press; I'm not sure how to do this, and searching the internet has led me to no answer as of yet.

Best Solution is,use Expandable Layout and add it inside your CardView.
<com.kyo.expandablelayout.ExpandableLayout
android:id="#+id/expandlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp" >
<ImageView
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="#null"
android:scaleType="centerCrop"
android:src="#drawable/parent" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:contentDescription="#null"
android:scaleType="centerCrop"
android:src="#drawable/child"
app:canExpand="true" />
</com.kyo.expandable.ExpandableLayout>

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"

How to create circle imageview with a transparent border?

I want to create an alert dialog same as shown in the image but I am stuck on how to create that center imageview with the transparent border.
Your dialog has some Views which resemble a BottomAppBar and a FloatingActionButton. Of course it is possible to write a custom View which looks just like a BottomAppBar, but it's easier to use the original thing.
You can use the following layout for the dialog (I left out the button bar because I think you already know you can achieve this with e.g. a LinearLayout):
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/bar"
android:layout_width="match_parent"
android:layout_height="96dp"
android:layout_gravity="bottom"
app:backgroundTint="#0000ff"
app:fabAlignmentMode="center"
app:fabCradleMargin="4dp"
app:fabCradleRoundedCornerRadius="0dp"
app:fabCradleVerticalOffset="4dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="12sp"
android:text="#string/lorem_string"
android:lines="3"
android:ellipsize="end"
android:padding="16dp"
android:layout_gravity="bottom"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="#id/bar"
app:elevation="0dp"/>
For more information on styling the BottomAppBar, see the developer documentation

ConstrainLayout not respecting the hierarchy

I have this layout
....................
<CheckBox
android:id="#+id/cb_remember_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textinput2"
android:text="#string/keep_login"
android:textColor="#android:color/holo_red_dark"
android:textSize="18sp"
android:layout_marginTop="14dp"
app:layout_constraintTop_toBottomOf="#+id/textinput2"
app:layout_constraintBottom_toTopOf="#+id/btn_signin_login" />
<Button
android:id="#+id/btn_signin_login"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/cb_remember_login"
android:backgroundTint="#color/colorAccent"
android:minHeight="75dp"
android:text="#string/signin"
android:textColor="#android:color/background_light"
android:textSize="30sp" android:visibility="visible"
android:layout_marginTop="36dp"
app:layout_constraintTop_toBottomOf="#+id/cb_remember_login"
app:layout_constraintBottom_toTopOf="#+id/tv_forgot_login"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
<include
layout="#layout/view_circle_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="#+id/btn_signin_login"
app:layout_constraintBottom_toBottomOf="btn_signin_login"
app:layout_constraintLeft_toLeftOf="#+id/btn_signin_login"
app:layout_constraintRight_toRightOf="#+id/btn_signin_login" />
<TextView
android:id="#+id/tv_forgot_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btn_signin_login"
android:text="#string/forgot_pass"
android:textAlignment="center"
android:textColor="#android:color/holo_red_dark"
android:textSize="18sp"
android:layout_marginTop="14dp"
app:layout_constraintTop_toBottomOf="#+id/btn_signin_login"
app:layout_constraintBottom_toTopOf="#+id/tv_copyrights_login"
tools:layout_editor_absoluteX="0dp" />
...........][1]][1]
Here is view_circle_progress.xml
<ProgressBar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:indeterminateTint="#color/red">
</ProgressBar>
You can see my included layout comes after the button but in the picture you can see it's actually beneath the button. Please help with a solution. Also except the included layout all the views are in a chain.
Go to your xml, click design. The on the upper left, corner you will see an icon similar to a blueprint. Click on it and you will get your layout as a blue print. Then click on the element that you want, you will see four points on all sides. Click on the upper point and drag it to the upper bar(menu, etc.). That way you will attach it and it will stay in place. If you want to make offset look on you right above the properties you will see a box representing the item with its constraints, just put the distance you want, and you will have your offset.
The problem was in Android 5.0 elevation is introduced. A button has a default elevation that's why it was always showing on top. Setting elevation value to my include layout solve the problem.

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.

How to fix EditText? [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
background layout moving when soft keyboard displayed - android
I have a layout file that contains severals views and EditText:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/connect"
android:id="#+id/btnConnect" android:layout_alignParentRight="true" android:layout_alignParentTop="true"/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/spServers"
android:layout_toLeftOf="#+id/btnConnect" android:layout_alignTop="#+id/btnConnect"
android:layout_alignBottom="#+id/btnConnect" android:layout_alignParentLeft="true"/>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnType" android:layout_alignLeft="#+id/btnConnect"
android:layout_below="#+id/btnConnect" android:layout_alignRight="#+id/btnConnect" android:textOff="#string/text"
android:textOn="#string/grid" />
<Spinner
android:layout_width="98dp"
android:layout_height="22dp"
android:id="#+id/spDataBases" android:layout_toLeftOf="#+id/btnConnect"
android:layout_below="#+id/btnConnect"
android:layout_alignBottom="#+id/btnType" android:layout_alignLeft="#+id/spServers"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/check"
android:id="#+id/btnCheck" android:layout_alignLeft="#+id/spServers" android:layout_alignParentBottom="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/run"
android:id="#+id/btnRun" android:layout_toRightOf="#+id/btnCheck" android:layout_alignTop="#+id/btnCheck"
android:layout_toLeftOf="#+id/btnLoad"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/load"
android:id="#+id/btnLoad" android:layout_alignRight="#+id/btnConnect"
android:layout_alignTop="#+id/btnCheck"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txtSQL" android:layout_alignLeft="#+id/spServers" android:layout_below="#+id/btnType"
android:layout_alignRight="#+id/btnConnect" android:layout_above="#+id/btnCheck"
android:gravity="left|top" android:singleLine="false" android:textAlignment="gravity"/>
</RelativeLayout>
It looks like this:
But when I'm trying to type something, I'm getting this problem:
Help me please to fix this. I don't wanna change the screen position on the layout, when I'm typing some text. It's moving up when user trying to type something.
You could try to tell Android to not resize your layout when the keyboard is brought up, making sure that what you're typing is visible. (Docs: http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft)
Add the following to your apps' manifest: (in the relevant activity instead of the dummy one below)
<activity android:name="Activity"
..
android:windowSoftInputMode="adjustPan"
..
</activity>
It's unclear to me if your issue is happening when you click on the EditText and the keyboard comes up, or if it only happens once you start typing? My answer will probably not help if the latter is the case. I'm also unsure if "adjustPan" is desirable behaviour, but it's worth a shot! It could also be a good idea to put your entire RelativeLayout in a ScrollView.

Categories