I have a linearlayout and a textview inside another linearlayout. The linearlayout from inside is displayed, but the problem is that the last textview is not. Why?
I have a LinearLayout and inside a FrameLayout and inside a SwipeRefreshLayout and in the middle a TextVeiw, but the problem is that TextView doesn't shows when I emulate the in the app. Why is that?
<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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SearchResults">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/content">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="50dp"
android:text="EXAMPLE TEXT" />
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
Picture below...
Change your xml file with this code
<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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SearchResults">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/content">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="50dp"
android:text="EXAMPLE TEXT" />
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
</LinearLayout>
Your frame Layout height is 0
set to match_parent
LinearLayout (main)
SwipeRefresh...
RelativeLayout (gravity center)
and then your Textview
The framelayout height is set to 0dp, kindly change that to match parent.
try this:
<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/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/content">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="EXAMPLE TEXT" />
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
it helps you
#George Patsias Change text color in textview
Related
I want to hide my Searchview when I scroll in my Fragment. I use a RecyclerView to retrieve my item and scroll them.
My fragment are actually like that:
When I scroll I want it to hide and then when I return to the top, I want it to show.
This is the xml of my Fragment:
<?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:orientation="vertical"
tools:context=".stock.StockFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.SearchView
android:id="#+id/search_view"
android:layout_width="341dp"
android:layout_height="34dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#drawable/search_layout"
android:gravity="center"
app:iconifiedByDefault="false"
app:queryHint="Cerca Articolo">
</androidx.appcompat.widget.SearchView>
</LinearLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycleViewStock"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
I tried to put it inside the Recycler but doesn't work, help please!
you can use NestedScrollView for scrolling all items.
<?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:orientation="vertical"
tools:context=".stock.StockFragment">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<androidx.appcompat.widget.SearchView
android:id="#+id/search_view"
android:layout_width="341dp"
android:layout_height="34dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#drawable/search_layout"
android:gravity="center"
app:iconifiedByDefault="false"
app:queryHint="Cerca Articolo">
</androidx.appcompat.widget.SearchView>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycleViewStock"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
After that set recyclerView.setNestedScrollingEnabled(false); in java for proper scrolling.
This is my code-
<?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=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/frame1"
android:layout_width="match_parent"
android:layout_height="300dp"
android:text="Recruitment Responses"
android:gravity="center"
android:textSize="30sp"
android:textColor="#fff"
android:background="#drawable/bg_rounded1"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:padding="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/frame1"
android:background="#f9fafc"/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
The scrolling is not smooth and is quite irritating can something be done to improve this? I want the textview to go up when scrolled upwards along with the Recycler View that is why i have nested both of them in a ScrollView and maybe that is what is creating an issue!
Adding a <androidx.core.widget.NestedScrollView> instead of ScrollView solves everything.
<?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=".MainActivity">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/frame1"
android:layout_width="match_parent"
android:layout_height="300dp"
android:text="Recruitment Responses"
android:gravity="center"
android:textSize="30sp"
android:textColor="#fff"
android:background="#drawable/bg_rounded1"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:padding="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/frame1"
android:background="#f9fafc"/>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>
try this inside your activity:
recyclerView.setNestedScrollingEnabled(false);
Try this :
recyclerView.setScrollView(true);
This help you to make recyclerView scrollview smooth.
I created a image slider using ViewPager and also added dot indicators to make the slider more interactive. However the dot indicators are below the images and I want the dot indicators to be on bottom overlapping the images.
My code is given below and I used the layout:weight element in layouts so the height of images changes according to the screen size.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10"
tools:context="com.example.navigationdrawerfragments.aboutSLFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="4.5">
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:id="#+id/SliderDots"
android:layout_below="#+id/viewPager"
android:orientation="horizontal"
android:gravity="center_vertical|center_horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5.3">
</LinearLayout>
</LinearLayout>
Current Result
Expected Result
Try something like this....
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10"
tools:context="com.example.navigationdrawerfragments.aboutSLFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4.5">
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:id="#+id/SliderDots"
android:layout_below="#+id/viewPager"
android:orientation="horizontal"
android:gravity="bottom"
android:layout_width="match_parent"
android:layout_height="30dp"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5.3">
</LinearLayout>
</LinearLayout>
This is most optimized XML layout for your case
You should use relative layout and can modify your XML like this, you can avoid using weights. As weight won't work with relative layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/activity_main"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:id="#+id/SliderDots"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginBottom="25dp"
android:orientation="horizontal"/>
</RelativeLayout>
You can use FrameLayout for this kind of view .You can overlap the slider dot over images .
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="#+id/activity_main"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:id="#+id/SliderDots"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginBottom="25dp"
android:orientation="horizontal"/>
</FrameLayout>
I'm trying to add CoordinatorLayoutincluding a Toolbar inside of a Fragment layout. But the problem is that the contents of the NestedScrollView Overlapping to the Toolbar, as you see in image below :
I tried to add a RelativeLayout parent and use
android:layout_below="#+id/coordinatorlayout" for the
NestedScrollView,but this make the content of NestedScrollView not
showing up.
Fragment layout Code :
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/coordinatorlayout"
android:layout_height="match_parent"
android:layout_width="match_parent">
<android.support.v7.widget.Toolbar
android:background="#color/colorPrimary"
android:id="#+id/toolbar2"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:contentInsetStart="0dp"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="#FFFFFF">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<android.support.v7.widget.CardView
android:layout_height="40dp"
android:layout_width="match_parent">
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<ImageView
android:id="#+id/search_icon"
android:layout_alignParentRight="true"
android:layout_height="24dp"
android:layout_width="24dp"
android:src="#drawable/ic_search_black_24dp" />
<EditText
android:hint="Search"
android:id="#+id/searchEditText"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CoordinatorLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginRight="50dp"
android:layout_marginLeft="50dp"
android:text="hello"/>
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</RelativeLayout>
1. Use CoordinatorLayout as root layout.
2. Add AppBarLayout and NestedScrollView inside CoordinatorLayout.
3. Put Toolbar inside AppBarLayout.
Here is the working code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
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.support.v7.widget.Toolbar
android:background="#color/colorPrimary"
android:id="#+id/toolbar2"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:contentInsetStart="0dp"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="#FFFFFF">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<android.support.v7.widget.CardView
android:layout_height="40dp"
android:layout_width="match_parent">
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<ImageView
android:id="#+id/search_icon"
android:layout_alignParentRight="true"
android:layout_height="24dp"
android:layout_width="24dp"
android:src="#drawable/ic_search_black_24dp" />
<EditText
android:hint="Search"
android:id="#+id/searchEditText"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginRight="50dp"
android:layout_marginLeft="50dp"
android:text="hello"/>
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
OUTPUT:
Hope this will help~
Thanks to #tompadre
The one and only solution was that i have to change the width="match_parent" of both CoordinatorLayout and NestedScrollView to wrap_content and the add this code below to NestedScrollView :
android:layout_below="#+id/coordinatorlayout"
a really simple problem wasted my time for an hour :/
This is my activity_main.xml
<?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="horizontal">
<include android:id="#+id/toolbar"
layout="#layout/toolbar"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_below="#+id/toolbar">
<FrameLayout
android:id="#+id/fragment_content"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
</LinearLayout>
My toolbar.xml:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
The fragment I send to fragment_content:
<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"
android:orientation="vertical"
android:background="#ffffff">
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipe_container"
android:layout_below="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Listview -->
<ListView
android:id="#+id/lvEvent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:divider="#D0D0D0"
android:dividerHeight="0.5dp"
android:showDividers="middle"/>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
Now the toolbar show up, I can do actions with it but there is nothing in my Framelayout? If I delete the include (toolbar) then I can see the content in my Framelayout. Anybody know what I'm doing wrong?
Given that you have set the height of your toolbar to wrap_content, I assume you want a vertical layout, but your top level LinearLayout is set to horizontal. Change the orientation to vertical.