Mercurial > dwindows
comparison android/DWindows.kt @ 2497:7b210f156eef
Android: Fix the notebook tabs visibility. Thank you orbyt on FreeNode for the help!
Set the TabLayout to ALIGN_PARENT_TOP or ALIGN_PARENT_BOTTOM and the ViewPager2 to
ABOVE or BELOW depending on the requested tab location. Not setting the relative
position of the ViewPager2 caused it to fill the entire layout.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 05 May 2021 01:19:21 +0000 |
parents | 3bf2f08fdc45 |
children | 4ae2b3b77f25 |
comparison
equal
deleted
inserted
replaced
2496:3bf2f08fdc45 | 2497:7b210f156eef |
---|---|
21 import android.widget.* | 21 import android.widget.* |
22 import android.widget.SeekBar.OnSeekBarChangeListener | 22 import android.widget.SeekBar.OnSeekBarChangeListener |
23 import androidx.appcompat.app.AlertDialog | 23 import androidx.appcompat.app.AlertDialog |
24 import androidx.appcompat.app.AppCompatActivity | 24 import androidx.appcompat.app.AppCompatActivity |
25 import androidx.collection.SimpleArrayMap | 25 import androidx.collection.SimpleArrayMap |
26 import androidx.core.view.marginStart | |
26 import androidx.recyclerview.widget.RecyclerView | 27 import androidx.recyclerview.widget.RecyclerView |
27 import androidx.viewpager2.widget.ViewPager2 | 28 import androidx.viewpager2.widget.ViewPager2 |
28 import com.google.android.material.tabs.TabLayout | 29 import com.google.android.material.tabs.TabLayout |
29 import com.google.android.material.tabs.TabLayout.OnTabSelectedListener | 30 import com.google.android.material.tabs.TabLayout.OnTabSelectedListener |
30 import com.google.android.material.tabs.TabLayoutMediator | 31 import com.google.android.material.tabs.TabLayoutMediator |
395 notebook.tag = dataArrayMap | 396 notebook.tag = dataArrayMap |
396 notebook.id = cid | 397 notebook.id = cid |
397 tabs.id = View.generateViewId() | 398 tabs.id = View.generateViewId() |
398 pager.id = View.generateViewId() | 399 pager.id = View.generateViewId() |
399 pager.adapter = DWTabViewPagerAdapter() | 400 pager.adapter = DWTabViewPagerAdapter() |
401 TabLayoutMediator(tabs, pager) { tab, position -> | |
402 //tab.text = "OBJECT ${(position + 1)}" | |
403 }.attach() | |
400 | 404 |
401 var params: RelativeLayout.LayoutParams = RelativeLayout.LayoutParams(w, h) | 405 var params: RelativeLayout.LayoutParams = RelativeLayout.LayoutParams(w, h) |
402 if(top != 0) { | 406 if(top != 0) { |
403 params.addRule(RelativeLayout.ABOVE, pager.id) | 407 params.addRule(RelativeLayout.ALIGN_PARENT_TOP) |
404 } else { | 408 } else { |
405 params.addRule(RelativeLayout.BELOW, pager.id) | 409 params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM) |
406 } | 410 } |
407 tabs.tabGravity = TabLayout.GRAVITY_FILL | 411 tabs.tabGravity = TabLayout.GRAVITY_FILL |
408 tabs.tabMode = TabLayout.MODE_FIXED | 412 tabs.tabMode = TabLayout.MODE_FIXED |
409 notebook.addView(tabs, params) | 413 notebook.addView(tabs, params) |
410 notebook.addView(pager, RelativeLayout.LayoutParams(w, w)) | 414 params = RelativeLayout.LayoutParams(w, w) |
415 if(top != 0) { | |
416 params.addRule(RelativeLayout.BELOW, tabs.id) | |
417 } else { | |
418 params.addRule(RelativeLayout.ABOVE, tabs.id) | |
419 } | |
420 notebook.addView(pager, params) | |
411 tabs.addOnTabSelectedListener(object : OnTabSelectedListener { | 421 tabs.addOnTabSelectedListener(object : OnTabSelectedListener { |
412 override fun onTabSelected(tab: TabLayout.Tab) { | 422 override fun onTabSelected(tab: TabLayout.Tab) { |
413 val adapter = pager.adapter as DWTabViewPagerAdapter | 423 val adapter = pager.adapter as DWTabViewPagerAdapter |
414 | 424 |
415 pager.currentItem = tab.position | 425 pager.currentItem = tab.position |