Implement non blocking progress dialog like playstore and facebook - android-asynctask

I am implementing custom progressDialog in my app where I am using animation-list to display a moving image but what I want to do is, embed my progressDialog in my activity such that it doesn't overlap on the screen and when the task is completed, view get updated whereas on back click activity finishes.

Create ProgressDialog within your activity and hide the other layout.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView style="?android:textAppearanceMedium"
android:lineSpacingMultiplier="1.2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/lorem_ipsum"
android:padding="16dp" />
</ScrollView>
<ProgressBar android:id="#+id/loading_spinner"
style="?android:progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
After fetching data from network call, hide the ProgressBar and show your data.

Related

How do i make the buttons from the following code be all the same size and occupy the entire gridLayout?

I have this grid layout which is part of an another grid layout, and contains 6 buttons.
It is next to a relative grid layout, if that makes any difference, thats why its width and height are set at 0dp.
How do I make them all the same size and make them fill the grid without using fixed values?
<android.support.v7.widget.GridLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0.5"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
app:columnCount="2"
app:rowCount="3"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:text="#string/pocetna_dugme_prijava_problema"
style="#style/StartMenuButton"
android:background="#drawable/rounded_corners_button_start_menu"
android:id="#+id/btnPrijavaProblemaLink"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/pocetna_dugme_prijava_ebill"
style="#style/StartMenuButton"
android:background="#drawable/rounded_corners_button_start_menu"
android:id="#+id/btnPrijavaEracunLink"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/pocetna_dugme_prijava_ukljucenje"
style="#style/StartMenuButton"
android:background="#drawable/rounded_corners_button_start_menu"
android:id="#+id/btnUkljucenjeLink"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/pocetna_dugme_prepaid_dopuna"
android:padding="0dp"
android:drawableBottom="#drawable/prepaid10"
style="#style/StartMenuButton"
android:background="#drawable/rounded_corners_button_start_menu"
android:id="#+id/btnPrepaidDopunaLink"/>
If you want the control to divide the screen space horizontally and vertically,you can use LinearLayout to achieve this, and set the android:layout_weight="1" property for the controls.
And to make the UI look better, you can also set android:layout_margin property.
You can refer to the following code:
<?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">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
>
<Button
android:layout_margin="5dp"
android:layout_weight="1"
android:text="button1"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button
android:layout_margin="5dp"
android:layout_weight="1"
android:text="button2"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:layout_margin="5dp"
android:layout_weight="1"
android:text="button3"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button
android:layout_margin="5dp"
android:layout_weight="1"
android:text="button4"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</LinearLayout>
You should change all your nested LinearLayouts to use ConstraintLayouts. Nested LinearLayouts inflate slowly, which was why ConstraintLayouts were created to replace them about 4-5 years ago. Android.Support.V7.Widgets were also dropped in favour of AndroidX controls at about the same time.

UIButton with Image and caption (title)

I have the problem if I add a image to a UIButton that the title is gone. I need a button with a caption below. Something like this:
Are there any solutions or custom views?
Try this
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="your image" />
<AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your Lable is here" />
</LinearLayout>

CoordinatorLayout scroll Tablayout itself

I want to have an activity, which contains a TabLayout and a Viewpager and some stuff below the Viewpager, which is visible in every Tab, and also scrollable.
When the recyclerview "tracks_recyclerview" is scrolled up, the TabLayout and the Edittext and the Viewpager hide as they should and the "all_tracks"-relativelayout and the horizontal Recyclerview stay at the top.
Here is what i want:
The content above the recyclerview should also be scrollable itself. So for now it is only possible to scroll down the "tracks_recyclerview". but the other parts of the view should also scroll down the list.
My Code looks something like this:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/content_activity"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/transparent">
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways"
app:tabContentStart="2dp"
app:tabGravity="fill"
app:tabIndicatorHeight="2dp"
app:tabMinWidth="24dp"
app:tabMode="fixed"
app:tabPadding="1dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways">
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="?attr/listPreferredItemHeight"
android:layout_margin="10dp"
app:layout_scrollFlags="scroll|enterAlways" />
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#444"
app:layout_scrollFlags="scroll|enterAlways"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/all_tracks"
android:layout_width="140dp"
android:layout_height="155dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="10dp">
<ImageView
android:id="#+id/cover"
android:layout_width="140dp"
android:layout_height="120dp"
android:paddingBottom="20dp"
android:paddingTop="20dp"
android:scaleType="fitCenter"
android:src="#drawable/abc_btn_rating_star_on_mtrl_alpha" />
<TextView
android:id="#+id/name"
android:layout_width="140dp"
android:layout_height="35dp"
android:layout_below="#+id/cover"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textSize="12sp" />
</RelativeLayout>
<?-- horizontal Recyclerview -->
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="155dp"
android:layout_marginBottom="10dp"
android:layout_toRightOf="#+id/all_tracks" />
</RelativeLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/tracks_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
I Hope you could understand my problem and maybe help me out.
Thanks,
Thomas
Edit: Is there somebody who can help me?

How to Scroll two ListView as one?

I Have two listviews Side by side but I want to scroll both listviews as one how can i do that?
Tried using OnClickListener but it does not seem to work?
I think best approach is to put each list view inside a LinearLayout and specified width on it. This works to display list views side by side. Careful with listviews filling its parent, the layout don't display as you expect. ListView may bypass the width parameter of the parent.
After that you need to put these LinearLayouts on Scrollview and you need set fillViewport. You can reach detailed info about fillViewport from here
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:background="#000000"
android:layout_width="match_parent"
android:fillViewport="true" <!-- here -->
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/linear1"
android:background="#FF0000"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:background="#00FF00"
android:id="#+id/linear2"
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="vertical" >
<ListView
android:id="#+id/ListView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#drawable/settingsMenuBorder"
android:scrollbars="none"
android:layout_marginTop="30dp"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:background="#0000FF"
android:id="#+id/linear3"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical" >
<ListView
android:id="#+id/ListView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#drawable/settingsMenuBorder"
android:scrollbars="none"
android:layout_marginTop="30dp"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>

android lollipop: content above tabs: scrolling issue

I have an activity just like Google NewsStand where there is an image above tabs. When the user starts scrolling up, the image and tabs start scrolling up (as if the scrolling is disabled for the contents under the tabs) and the contents of the tab start scrolling once the image above the tabs goes past the screen. All this happens in one scroll motion. See Google NewsStand app for what I'm talking.how can this be achieved?
I'm using appcompat-21 and toolbar for the material look. Thanks a lot for answering this...
Below is the sample code (based on SlidingTabsBasic)
ACTIVITY_MAIN.XML
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/sample_main_layout">
<FrameLayout
android:id="#+id/sample_content_fragment"
android:layout_weight="2"
android:layout_width="match_parent"
android:layout_height="0px" />
FRAGMENT_SAMPLE.XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:layout_height="200dp" android:layout_width="wrap_content"
android:text="some random text"/>
<com.example.android.common.view.SlidingTabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="#android:color/white"/>
</LinearLayout>
PAGER_ITEM.XML
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/item_subtitle"
android:layout_width="wrap_content"
android:layout_height="400dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Page:"/>
<TextView
android:id="#+id/item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="80sp" />
</LinearLayout>
</ScrollView>
This code as is allows you to scroll contents vertically within the tabs. I also want to scroll the content of the entire screen first before scrolling the tabs, just like in the NewsStand app, all in one scroll motion. How do I achieve this?

Resources