Is there any way to add a favourite button on the image? - kotlin

I'm currently working on mobile application by using the kotlin language. May I know is it possible to add a favorite button on the image that the user can click it? If it is possible, then how is it?
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="#+id/toggleButtonGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="#+id/ic_favorite"
style="#style/ToggleButtonWithIconOnly"
app:icon="#drawable/ic_favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</com.google.android.material.button.MaterialButtonToggleGroup>
<ImageView
android:id="#+id/cake"
android:layout_width="300dp"
android:layout_height="200dp"
android:layout_marginTop="30dp"
android:layout_marginStart="55dp"
app:srcCompat="#drawable/fgh" />

Related

How to make a part of image in textview as clickable using Kotlin?

I found that I can add a image by using android:drawableRight
then how can I make image as clickable in textview?
<TextView
android:id="#+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:padding="5dp"
android:text="title"
android:drawableRight="#drawable/ic_baseline_delete_24"
android:drawablePadding="5dp"
android:clickable="true"
android:textSize="18sp" />

Image not appear using splash screen react native

i want to put image in splash screen react native but it didnt work. im using this library https://github.com/crazycodeboy/react-native-splash-screen
i put some text in it and it works fine. but the image doesnt appear at all. i tried it in android studio it works fine but when react native rendering image not appear at all
Image : png 32 bit
Here is it the code
<?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:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical"
android:background="#color/white"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
app:srcCompat="#drawable/splash" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="7dp"
android:text="Tes"
android:textColor="#4972D1"
android:textSize="24sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="7dp"
android:text="Tes"
android:textColor="#759fff"
android:textSize="24sp" />
</LinearLayout>
Here is it in android studio
Here is it when i launch the app
According to the official docs, you should add scaleType property to your ImageView.
android:scaleType="centerCrop"
If it doesn't works please add your manifest file for further help.
You also need to add in the image in Splash.xml and then re-build the project.
Also add the images in drawable folder.

Put a button at the end of a recyclerview with swiperefreshlayout

i want to to put a button at the end of a scrollview, i know that i can achieve this if i modify my adapter but i don't want to do it in that way because i think there's an easier way. So i tried modifying my layout like this:
<!-- Not important stuff -->
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/refreshIndicatorCoins"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/rvCoinsFull"
android:clickable="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
This works almost perfect but swipeRefresh's animation freezes
Hope it helps.
After RecyclerView put this code.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RelativeLayout>

Android XML adapted for all scree sizes

I am currently developing an android application and am facing a problem.
I am aware that the most common thing to adapt your application to most of the devices is to create different folder named "layout-small", "layout-normal", etc. in order to handle this issue.
However, this does not solve everything : both Samsung S2 and Samsung S3 and considered "normal" screen size, but the given result is very different, even though I also use "dp" to set height and with of most of my views.
How can I adapt my xml for EVERY device PERFECTLY ? I don't mind having the same xml file for every different device, but how do I do that ?
Here is an example of an XML file that renders welle on S3, but is cut down on S2 (the last button appears partially)
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:useDefaultMargins="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Me"
android:id="#+id/textView"
style="#style/title_parameters"
android:layout_alignParentTop="true"
/>
<Button
android:id="#+id/btUpdateProfile"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="Update profile"
android:textColor="#drawable/text_color_selected_parameters"
style="#style/button_text"
android:background="#drawable/solo_button_parameters"
android:drawableRight="#drawable/table_view_cell_accessory_disclosure_indicator"
android:layout_below="#+id/textView"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Friends"
android:id="#+id/textView2"
style="#style/title_parameters"
android:layout_below="#+id/btUpdateProfile"/>
<Button
android:id="#+id/btFindFriends"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="Find friends"
android:textColor="#drawable/text_color_selected_parameters"
style="#style/button_text"
android:background="#drawable/solo_button_parameters"
android:drawableRight="#drawable/table_view_cell_accessory_disclosure_indicator"
android:layout_below="#+id/textView2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Setting"
android:id="#+id/textView3"
style="#style/title_parameters"
android:layout_below="#+id/btFindFriends"/>
<Button
android:id="#+id/btSharing"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="Sharing"
android:gravity="top"
android:textColor="#drawable/text_color_selected_parameters"
style="#style/button_text"
android:background="#drawable/top_corner_button_parameters"
android:drawableRight="#drawable/table_view_cell_accessory_disclosure_indicator"
android:layout_below="#+id/textView3"/>
<Button
android:id="#+id/btPushNotification"
android:layout_width="fill_parent"
android:layout_height="50dp"
style="#style/button_text"
android:textColor="#drawable/text_color_selected_parameters"
android:text="Push notification"
android:layout_marginTop="-2dp"
android:background="#drawable/rectangle_button_parameters"
android:drawableRight="#drawable/table_view_cell_accessory_disclosure_indicator"
android:layout_below="#+id/btSharing"/>
<Button
android:id="#+id/btAutomation"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:gravity="bottom"
android:text="Automation"
style="#style/button_text"
android:background="#drawable/bottom_corner_button_parameters"
android:drawableRight="#drawable/table_view_cell_accessory_disclosure_indicator"
android:layout_below="#+id/btPushNotification"
android:textColor="#drawable/text_color_selected_parameters"
android:layout_marginTop="-2dp"/>
<Button
android:id="#+id/btDisconnect"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="Disconect"
android:layout_marginTop="20dp"
android:textColor="#drawable/text_color_selected_parameters"
style="#style/button_text"
android:background="#drawable/solo_button_parameters"
android:drawableLeft="#drawable/disconnect"
android:layout_below="#+id/btAutomation"
android:layout_marginBottom="30dp"/>
</RelativeLayout>
I will upload screen shots as soon as I can.
Once again, my question is : how can I have an XML file for every existing device ?
Can you please post some code. It will be better.
Without define fixed size relative layout and use its positional attributes properly. (This is a comment )

android, how to place a scroll view in the middle of the screen:

I'm trying to create a a screen layout of the following though:
A line with some TextView in it
A scroll view where the user actions will add or remove View from
A buttons line.
I have no problem with 1. or 3. But 2. gives me troubles. My scheme is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainX"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/labels"
android:layout_weight="1">
<!--Some text view of various sizes -->
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/dataScroll">
<LinearLayout
android:id="#+id/dataShow"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/buttons"
android:layout_weight="1">
<!--some buttons-->
</LinearLayout>
</LinearLayout>
When I run the program, the buttons line is in the middle of the screen and When I add element to the screen (using the addView on the dataShow layout), the frist one is added without a problem but after that I can't tell what is happening.
Thanks
I'm not exactly sure what you are trying to do.
It seems like you want to dynamically add items to the dataShow layout. Instead of using a ScrollView containing a LinearLayout, you should be using a ListView (vertical scrolling) or Gallery (horizontal scrolling) for your dataShow layout. This will provide the scroll functionality and allow you to add items dynamically to the list/gallery.
Try using a RelativeLayout, then align the header at the top, and the footer at the bottom. Set the ScrollView paddingBottom.
<?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">
<TextView
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="text"
android:textAlignment="center"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/header"
android:layout_above="#+id/footer"
android:paddingBottom="100dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="center main content"
android:textAlignment="center"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"/>
</ScrollView>
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#color/colorPrimary"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="text"
android:textAlignment="center"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"/>
</RelativeLayout>
</RelativeLayout>