How to increase tab height in xml without changing position. Also viewpager goes behind tab layout

huangapple go评论78阅读模式
英文:

How to increase tab height in xml without changing position. Also viewpager goes behind tab layout

问题

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    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:id="@+id/root">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.NoActionBar.AppBarOverlay">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/bgColor"
            app:popupTheme="@style/AppTheme.PopupOverlay">

            <TextView
                android:id="@+id/tv_selected_chat"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:gravity="center_vertical"
                android:text="0"
                android:textColor="@color/colorWhite"
                android:textSize="17sp"
                android:visibility="gone" />

        </androidx.appcompat.widget.Toolbar>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.viewpager.widget.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="644dp"
        android:paddingBottom="20dp"
        ads:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:showIn="@layout/activity_main">

    </androidx.viewpager.widget.ViewPager>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/open_new_chat_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_marginRight="27dp"
        android:layout_marginBottom="84dp"
        android:tint="@color/colorWhite"
        android:visibility="visible"
        app:backgroundTint="@color/colorAccent"
        app:fabSize="normal"
        app:layout_anchor="@id/view_pager"
        app:layout_anchorGravity="bottom|right|end"
        app:srcCompat="@drawable/ic_message" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/text_status_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_marginRight="27dp"
        android:layout_marginBottom="84dp"
        android:tint="@color/colorWhite"
        android:visibility="invisible"
        app:backgroundTint="@color/colorGreen"
        app:fabSize="normal"
        app:layout_anchor="@id/view_pager"
        app:layout_anchorGravity="bottom|right|end"
        app:srcCompat="@drawable/ic_edit" />

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="65dp"
        android:background="@color/bgColor"
        ads:layout_anchor="@+id/view_pager"
        ads:layout_anchorGravity="bottom|center"
        ads:tabBackground="@color/actionModeBackground"
        ads:tabIndicatorColor="@color/audio_wave_background"
        ads:tabIndicatorHeight="2dp"
        app:tabGravity="fill"
        app:tabMaxWidth="0dp"
        app:tabMode="fixed"
        app:tabSelectedTextColor="@android:color/white" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
英文:

Please help me. I have a tab layout and a viewpager. I have 2 problems. I want to decrease the height of tablayout. Also while scrolling(a list view in the page) as the viewpager is behind tab layout , the tab layout hides some elements of the list. Please help me solve the problem!!!

The problem can be resolved but i dont know how. Please hep me soon.I have tried many ways but nothing solved it. Also send the entire corrected code as answer
If i just set the layoutheight of the tab layout... this happens...
See there is a white line below the bottom grey color tablayout

How to increase tab height in xml without changing position. Also viewpager goes behind tab layout

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
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:id="@+id/root">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.NoActionBar.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/bgColor"
app:popupTheme="@style/AppTheme.PopupOverlay">
<!--app:layout_scrollFlags="scroll|snap"-->
<TextView
android:id="@+id/tv_selected_chat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:gravity="center_vertical"
android:text="0"
android:textColor="@color/colorWhite"
android:textSize="17sp"
android:visibility="gone" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="644dp"
android:paddingBottom="20dp"
ads:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main">
</androidx.viewpager.widget.ViewPager>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/open_new_chat_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginRight="27dp"
android:layout_marginBottom="84dp"
android:tint="@color/colorWhite"
android:visibility="visible"
app:backgroundTint="@color/colorAccent"
app:fabSize="normal"
app:layout_anchor="@id/view_pager"
app:layout_anchorGravity="bottom|right|end"
app:srcCompat="@drawable/ic_message" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/text_status_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginRight="27dp"
android:layout_marginBottom="84dp"
android:tint="@color/colorWhite"
android:visibility="invisible"
app:backgroundTint="@color/colorGreen"
app:fabSize="normal"
app:layout_anchor="@id/view_pager"
app:layout_anchorGravity="bottom|right|end"
app:srcCompat="@drawable/ic_edit" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="65dp"
android:background="@color/bgColor"
ads:layout_anchor="@+id/view_pager"
ads:layout_anchorGravity="bottom|center"
ads:tabBackground="@color/actionModeBackground"
ads:tabIndicatorColor="@color/audio_wave_background"
ads:tabIndicatorHeight="2dp"
app:tabGravity="fill"
app:tabMaxWidth="0dp"
app:tabMode="fixed"
app:tabSelectedTextColor="@android:color/white" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

答案1

得分: 2

你可以像这样使用硬编码的高度值,比如20dp等,根据你的需要。同时,将你的ViewPager移到AppBar布局的上方,并使用以下代码:

<androidx.viewpager.widget.ViewPager
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="644dp"
    android:paddingBottom="20dp"
    ads:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main"/>

仔细看你的代码,你没有使用这个,而是使用了以下内容:

<androidx.viewpager.widget.ViewPager
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="644dp"
    android:paddingBottom="20dp"
    ads:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main">
  
   </androidx.viewpager.widget.ViewPager>

这意味着你在这个区域添加了一些布局等内容。

英文:

you can use hardcode value of height as like 20dp etc as much you require. also move your view pager upside appbar layout and use this code

&lt;androidx.viewpager.widget.ViewPager
android:id=&quot;@+id/view_pager&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;644dp&quot;
android:paddingBottom=&quot;20dp&quot;
ads:layout_behavior=&quot;@string/appbar_scrolling_view_behavior&quot;
tools:showIn=&quot;@layout/activity_main&quot;/&gt;
look at your code you dont use this instead of using this
&lt;androidx.viewpager.widget.ViewPager
android:id=&quot;@+id/view_pager&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;644dp&quot;
android:paddingBottom=&quot;20dp&quot;
ads:layout_behavior=&quot;@string/appbar_scrolling_view_behavior&quot;
tools:showIn=&quot;@layout/activity_main&quot;&gt;
&lt;/androidx.viewpager.widget.ViewPager&gt;

it means you are using this area to add some layout etc.

huangapple
  • 本文由 发表于 2020年10月6日 11:51:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/64219100.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定