There is a tabhost that contains 3 elements. How to make swipe between them?
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/tasks1">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/tasks2" >
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/tasks3">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
If you alter this option does not work, then how to do this with a tabbed activity(i need to swipe between the 3 elements)? Thanks in advance.
Related
I use android:textIsSelectable="true" for TextView.
To enabled copy/select/paste For TextView it is OK
Issue
When I open this activity, it scrolls to middle automatically, like this Link
Why did this problem happen?
This is my layout code.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res/android" >
<data>
<variable
name="aboutMbti"
type="mbtitest.kiars.me.mbti.model.AboutMbti"/>
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardBackgroundColor="#android:color/white"
app:cardCornerRadius="2dp"
app:cardElevation="5dp" >
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:fitsSystemWindows="true"
android:scrollbarSize="1dp"
android:scrollbarThumbVertical="#android:color/white">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/img_splash_mtbi"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="3dp"
android:adjustViewBounds="true"
android:padding="5dp"
android:scaleType="centerCrop"
bind:imageUrl="#{aboutMbti.imageUrl}"/>
<TextView
android:id="#+id/txt_content_about_mtbi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/img_splash_mtbi"
android:layout_margin="5dp"
android:textIsSelectable="true"
android:padding="#dimen/title_padding"
android:text="#{aboutMbti.textContent}"
android:textColor="#color/ques_title"
android:textSize="15sp"
android:textStyle="bold"/>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</androidx.cardview.widget.CardView>
</RelativeLayout>
</layout>
Solution
You can add either android:focusableInTouchMode="true" or android:descendantFocusability="blocksDescendants" to the child layout in NestedScrollView
Try below code in your layout:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
...... >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true" >
...........
Finally, According to https://stackoverflow.com/users/6891563/khemraj comment, I Find
Mey solution ...
Just add android:focusableInTouchMode="true" to ImageView Like this :
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res/android" >
<data>
<variable
name="aboutMbti"
type="mbtitest.kiars.me.mbti.model.AboutMbti"/>
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardBackgroundColor="#android:color/white"
app:cardCornerRadius="2dp"
app:cardElevation="5dp" >
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:fitsSystemWindows="true"
android:scrollbarSize="1dp"
android:scrollbarThumbVertical="#android:color/white">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/img_splash_mtbi"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="3dp"
android:adjustViewBounds="true"
android:padding="5dp"
android:focusableInTouchMode="true"
android:scaleType="centerCrop"
bind:imageUrl="#{aboutMbti.imageUrl}"/>
<TextView
android:id="#+id/txt_content_about_mtbi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/img_splash_mtbi"
android:layout_margin="5dp"
android:textIsSelectable="true"
android:padding="#dimen/title_padding"
android:text="#{aboutMbti.textContent}"
android:textColor="#color/ques_title"
android:textSize="15sp"
android:textStyle="bold"/>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</androidx.cardview.widget.CardView>
</RelativeLayout>
</layout>
Tnx Guys
how to add the search bar in the listView to hide it when Scrolling?
Here my code xml:
<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">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="50dp">
<SearchView
android:id="#+id/maBtnSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:iconifiedByDefault="false"
android:queryHint="Search User" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/listView">
</ListView>
</LinearLayout>
This is my complete layout code above, thank you for helping me
Try this. Here searchview is put on toolbar. Change code according to your usage.
<android.support.design.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:id="#+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:background="#drawable/back"
android:id="#+id/pager_sessions"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v4.view.ViewPager>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:id="#+id/search_edit_frame"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_sessions"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways">
<android.support.v7.widget.SearchView
android:id="#+id/search_item"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</android.support.v7.widget.SearchView>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
app:layout_scrollFlags="scroll|enterAlways"
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:tabIndicatorColor="#android:color/background_light"
app:tabSelectedTextColor="#android:color/background_light"
app:tabTextColor="#android:color/background_light">
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
I am new to android programming and I am trying to scroll my recycler view over image
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootRL"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="160dp"
android:background="#drawable/mydrawable">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="160dp"
android:id="#+id/rv"/>
</FrameLayout>
When I scroll ,the recycler view scrolls under the image not over it.How can i achieve this effect ?
Try this:-
Using FrameLayout by setting backgroundImage:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootRL"
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_marginTop="160dp"
android:background="#drawable/tips"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
Using LinearLayout by setting backgroundImage:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootRL"
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_marginTop="160dp"
android:background="#drawable/tips"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Using RelativeLayout by setting backgroundImage:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootRL"
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_marginTop="160dp"
android:background="#drawable/tips">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Using RelativeLayout with ImageView:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootRL"
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_marginTop="160dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/tips" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Having an issue with Android Studio. Basically, I'm doing as it says however it's producing an error which I can't figure out.
I have tried using android:id="android:id/tabs". Alas this did not work either
Here is the XML:
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".FindMyCar"
android:id="#+id/">
<TabHost
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tabHost"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget
android:id="android:id_tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/tabFind"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="#+id/tabRandom"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"></LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</RelativeLayout>
I have tried using android:id="android:id/tabs"
It should be android:id="#android:id/tabs"
I am trying to add action bar on top, and two containers below the action bar, each of the containers I want to have 80% of width and 20% of width.
Here is my XML file which is not working:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.hany_action_bar.MainActivity"
tools:ignore="MergeRootFrame" >
<LinearLayout
android:id="#+id/menu_container"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:weightSum="20"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:id="#+id/main_container"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:weightSum="80"
android:orientation="horizontal" >
</LinearLayout>
</FrameLayout>
Can try like this :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2"
tools:context="com.example.hany_action_bar.MainActivity"
tools:ignore="MergeRootFrame" >
<LinearLayout
android:id="#+id/menu_container"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1.6"
android:background="#000"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:id="#+id/main_container"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="0.4"
android:background="#fff"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>