I want use this library into my project : Library
My problem is how to enter the containerLayout, I got this code :
StikkyHeaderBuilder.stickTo(mListView)
.setHeader(R.id.header, containerLayout)
.minHeightHeader(250)
.build();`
my xml code :
<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"
tools:context=".MainActivity">
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="230dp">
<ImageView
android:id="#+id/header_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/main_header" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="G Vision"
android:textSize="30sp"
android:textColor="#android:color/white"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"/>
</RelativeLayout>
I saw a demo of the source, but the fragment used in the demo, and I want to use my activity.
How I should fill the container layer?
set id for the most outer RelaytiveLayout.
in your activity make object
RelativeLayout containerLayout = (RelaytiveLayout) findViewById(R.id.rel_id);
then put this in here
StikkyHeaderBuilder.stickTo(mListView)
.setHeader(R.id.header, containerLayout)
.minHeightHeader(250)
.build();
Related
I have an image above my listview that is currently doing nothing.But I want my image to be animated when the user scrolls in the listview just like
this.
This is an example of an old library called StikkyHeader ,but it doesn't seem to work now.
Is there any other libraries for the same reason or even a way I can do it without libraries?
Try this one
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:minHeight="200dp"
>
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="#+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:minHeight="150dp"
app:expandedTitleMarginBottom="25dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
>
<ImageView
android:layout_width="match_parent"
android:src="#drawable/magic_bg"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.5"
android:layout_height="match_parent"/>
<TextView
android:layout_width="match_parent"
android:text="#KeepMakingMagic"
android:textSize="25dp"
android:gravity="center"
android:textColor="#color/white"
android:textStyle="bold"
app:layout_collapseMode="parallax"
android:layout_marginBottom="50dp"
android:layout_gravity="bottom"
app:layout_collapseParallaxMultiplier="-0.1"
android:layout_height="wrap_content"/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<!-- You can have list view here Instead of scrollview But you need to make sure layout behaviour is same-->
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorAccent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:background="#color/colorAccent"
android:layout_height="1000dp">
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Demo :
Don't forget to play with things
i have a little problem. I have a n number of fragments and i want to put this fragments in a row, but when the screen runs out, the rest goes to the bottom line, and so on.
I'm doing this:
for (int i = 0; i < n ; i++) {
PresencaFragment aFragment = new PresencaFragment("Test "+i, "2017059227_11.jpg", 2017000000);
getSupportFragmentManager().beginTransaction().add(R.id.frag, aFragment).commit();
}
And the code of my fragment and home fragment (i put this n fragments in home fragment) is:
HomeFragment:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/txtHoras"
android:layout_marginTop="125dp"
android:focusable="true"
android:text="A carregar dados..."
android:textColor="#color/corescola"
android:textSize="25dp"
android:layout_height="40dp"
android:layout_width="match_parent"
android:textAlignment="center"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_marginTop="145dp"
android:layout_marginBottom="5dp">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/frag"
>
</TableLayout>
</ScrollView>
</RelativeLayout>
And my fragment code's:
<FrameLayout 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=".PresencaFragment">
<TableLayout
android:layout_width="391dp"
android:layout_height="264dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="20dp"
android:layout_marginRight="8dp"
android:stretchColumns="1">
<TableLayout
android:layout_width="match_parent"
android:layout_height="252dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="10dp"
android:stretchColumns="1">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:background="#7EC5CAE9"
android:minHeight="55dp">
<TextView
android:id="#+id/txt_nomeAluno"
android:layout_width="378dp"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:width="300dp"
android:text="Student Name"
android:textAlignment="center"
android:textColor="#000"
android:textSize="24dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eee"
android:minHeight="35dp">
<TextView
android:id="#+id/txt_numero"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:width="300dp"
android:padding="10dp"
android:text="Student number: xxxxxxxxx"
android:textAlignment="center"
android:textColor="#000"
android:textSize="20dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eee"
android:minHeight="35dp">
<ImageView
android:id="#+id/imagem"
android:layout_width="371dp"
android:layout_height="match_parent"
tools:src="#tools:sample/avatars" />
</TableRow>
</TableLayout>
</TableLayout>
</FrameLayout>
So, i want this but obtain this:
image of what i want and what i obtain
You're passing the R.id.frag when starting a fragment. As far as I see, the R.id.frag is the ID of the whole table layout, which means you're replacing whole table with the fragment. What you want is to set each fragment in the correct row id.
Note: having fragments in the table is really a bad practice. If you need a table layout, you should use views within it, check some tutorial about it, like this: https://abhiandroid.com/ui/tablelayout
My app has a banner ad at the bottom.It takes some time load.While it loads a white space appears in its place as shown below:
How do i slove this problem.Should improve the loading speed of the banner ad or do something with my xml layout.
Here is the 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"
tools:context="com.example.android.gametalks.MainActivity"
>
<LinearLayout
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/no_internet_view"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No Internet Connection!"/>
<Button
android:id="#+id/retry_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Retry"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_above="#id/adView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
></ListView>
</LinearLayout>
</LinearLayout>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
You can remove android:layout_above="#id/adView from list container and add to your ListView paddingBottom = height_of_your_banner (or about it) and add android:clipToPadding="false". Now your listview will fill whole screen and if you scroll to bottom - you will be able to see al items without overlap from banner. Also you can remove odd containers from ListView so instead of:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_above="#id/adView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
></ListView>
</LinearLayout>
</LinearLayout>
Will be just:
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
I am trying to get the empty.xml layout display when the adapter listview is empty.
I tried with http://cyrilmottier.com/2011/06/20/listview-tips-tricks-1-handle-emptiness/
But I can't do it.
empty.xml
<LinearLayout 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:orientation="vertical"
tools:context=".Principal"
>
<ListView
android:id="#+id/listview_items"
tools:listitem="#layout/item_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="1px"
android:divider="#ebebeb"
android:scrollbarStyle="insideOverlay"
>
</ListView>
<ViewStub
android:id="#+id/stub_import"
android:layout="#layout/empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
</LinearLayout>
main.xml
<LinearLayout 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:orientation="vertical"
tools:context=".Principal"
>
<ListView
android:id="#+id/listview_items"
tools:listitem="#layout/item_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="1px"
android:divider="#ebebeb"
android:scrollbarStyle="insideOverlay"
>
</ListView>
<ViewStub
android:id="#+id/stub_import"
android:layout="#layout/empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
</LinearLayout>
I know the command to inflate and deflate is something.
((ViewStub) findViewById(R.id.stub_import)).setVisibility(View.VISIBLE);
// or
View importPanel = ((ViewStub) findViewById(R.id.stub_import)).inflate();
Where should I put the command to inflate when my listview is empty?
Thanks in advance.
Personally i do these in either of onCreate or onResume, by first checking if my listview is empty using the listview's adapter.getCount() method to check if the adapter is empty , then i inflate the viewStub.
My code looks like this :
if(adapter.getCount()==0){
ViewStub stub=(ViewStub) viewRoot.findViewById(R.id.viewstub);
stub.inflate();
}
My XML file looks Like
<LinearLayout
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"
tools:context="com.younickacademy.younickmobile.Fragment_AlertsList"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ListView
android:id="#+id/listview_alerts"
android:layout_width="fill_parent"
android:layout_height="fill_parent"></ListView>
<ViewStub
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout="#layout/empty_alert_list"
android:id="#+id/viewstub"/>
</FrameLayout>
<Button
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="bottom|right"
android:layout_margin="10dp"
android:id="#+id/btn_new_alert"
android:elevation="6dp"
android:gravity="center"
android:text="+"
android:textColor="#color/textColorPrimary"
android:background="#drawable/circular_button_selector"/>
</LinearLayout>
And My empty_alert_list.xml layout looks like :
<?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:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="No Emergency Alerts have been received Yet."
android:textStyle="bold"
android:gravity="center_horizontal"
/>
</RelativeLayout>
However this may not be the best implementation, but does solve my problem momentarily until a better hack is found.
Im trying to show / hide a specifically ImageView, that it's inside a FrameLayout. At the same time, im gonna hide or show (on the contrary to ImageView), the LinearLayout with id recents_linear_layout
<com.android.systemui.recent.RecentsPanelView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/recents_root"
android:layout_height="match_parent"
android:layout_width="match_parent">
<FrameLayout
android:id="#+id/recents_bg_protect"
android:background="#drawable/status_bar_recents_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:clipToPadding="false"
android:clipChildren="false">
<com.android.systemui.recent.RecentsHorizontalScrollView android:id="#+id/recents_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="#dimen/status_bar_recents_right_glow_margin"
android:divider="#null"
android:stackFromBottom="true"
android:fadingEdge="horizontal"
android:scrollbars="none"
android:fadingEdgeLength="#dimen/status_bar_recents_fading_edge_length"
android:layout_gravity="bottom|left"
android:orientation="horizontal"
android:clipToPadding="false"
android:clipChildren="false">
<LinearLayout android:id="#+id/recents_linear_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:clipToPadding="false"
android:clipChildren="false">
</LinearLayout>
</com.android.systemui.recent.RecentsHorizontalScrollView>
**<ImageView android:id="#+id/landscape"
android:gravity="center"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0.0dip"
android:src="#drawable/landscape_img"
android:visibility="gone" />**
</FrameLayout>
<include layout="#layout/status_bar_no_recent_apps"
android:id="#+id/recents_no_apps"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" />
</com.android.systemui.recent.RecentsPanelView>
My java code, throws a NullPointerException, because it cant find the ImageView (because this is being executed on com.android.systemui.recent.RecentsHorizontalScrollView. This is the code
mLinearLayout = (LinearLayout) findViewById(R.id.recents_linear_layout);
mLinearLayout.setVisibility(mRecent ? LinearLayout.GONE : LinearLayout.VISIBLE);
mLandScape = (ImageView) findViewById(R.id.landscape);
mLandScape.setVisibility(mRecent ? View.VISIBLE : View.GONE);
Thanks in advance.
you could use ((Activity)getContext()).findViewById(R.id.landscape) though you should avoid it since there is no guarantee that the context is an activity. I can't understand why you are trying to hide some views inside this view. I think this is the activity's responsibility. You should make some interface with call back method to notify the activity about your event then let it hide the image view.
FIXED
Fix was making a external layout container with old Layout and ImageView as childs
<com.android.systemui.recent.RecentsHorizontalScrollView android:id="#+id/recents_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="#dimen/status_bar_recents_right_glow_margin"
android:divider="#null"
android:stackFromBottom="true"
android:fadingEdge="horizontal"
android:scrollbars="none"
android:fadingEdgeLength="#dimen/status_bar_recents_fading_edge_length"
android:layout_gravity="bottom|left"
android:orientation="horizontal"
android:clipToPadding="false"
android:clipChildren="false">
<LinearLayout android:id="#+id/child_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:clipToPadding="false"
android:clipChildren="false">
<LinearLayout android:id="#+id/recents_linear_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:clipToPadding="false"
android:clipChildren="false" />
<ImageView android:id="#+id/sense_landscape"
android:gravity="center"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0.0dip"
android:src="#drawable/sense_landscape"
android:visibility="visible" />
</LinearLayout>
</com.android.systemui.recent.RecentsHorizontalScrollView>