簡體   English   中英

Android:TabLayout如何以編程方式將height設置為0?

[英]Android: TabLayout how set height = 0 programatically?

這是我的TabLayout xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
    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.TabLayout
         android:id="@+id/tabLayout"
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_marginTop="20dp"
         android:background="@android:color/white"
         android:minHeight="@dimen/standard_min_height_container"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent"
         app:tabGravity="fill"
         app:tabIndicatorHeight="0dp"
         app:tabMode="fixed"
         app:tabSelectedTextColor="@color/colorPrimaryDark"/>

<ViewPager
    android:id="@+id/customViewPager"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    app:layout_constraintLeft_toLeftOf="@+id/tabLayout"
    app:layout_constraintRight_toRightOf="@+id/tabLayout"
    app:layout_constraintTop_toBottomOf="@+id/tabLayout" />

</android.support.constraint.ConstraintLayout>

如何以編程方式更改TabLayout.android:layout_height = 0

嘗試這個

  • 對於Constraint Layout您必須通過簡單地執行此操作來更改高度和寬度

     tabLayout=(TabLayout)findViewById(R.id.tabLayout); ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) tabLayout.getLayoutParams(); // Changes the height and width to the specified *pixels* params.height = 500; params.width = 500; tabLayout.setLayoutParams(params); 

輸出

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM