Mercurial > dwindows
comparison android/DWindows.kt @ 2568:b536b7b21682
Android: Switch to using LinearLayout for Container row layout...
Would like to use ContraintLayout or RelativeLayout so we can stack text columns vertically...
However I couldn't get ConstraintLayout to work so switching for the moment.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 19 May 2021 23:22:51 +0000 |
parents | 19d82c1f135f |
children | bbe693293be5 |
comparison
equal
deleted
inserted
replaced
2567:19d82c1f135f | 2568:b536b7b21682 |
---|---|
639 override fun getItemId(position: Int): Long { | 639 override fun getItemId(position: Int): Long { |
640 return position.toLong() | 640 return position.toLong() |
641 } | 641 } |
642 | 642 |
643 override fun getView(position: Int, view: View?, parent: ViewGroup): View { | 643 override fun getView(position: Int, view: View?, parent: ViewGroup): View { |
644 var rowView: ConstraintLayout? = view as ConstraintLayout? | 644 var rowView: LinearLayout? = view as LinearLayout? |
645 var displayColumns = model.numberOfColumns() | 645 var displayColumns = model.numberOfColumns() |
646 | 646 |
647 // In simple mode, limit the columns to 1 or 2 | 647 // In simple mode, limit the columns to 1 or 2 |
648 if(simpleMode == true) { | 648 if(simpleMode == true) { |
649 // If column 1 is bitmap and column 2 is text... | 649 // If column 1 is bitmap and column 2 is text... |
655 } | 655 } |
656 } | 656 } |
657 | 657 |
658 // If the view passed in is null we need to create the layout | 658 // If the view passed in is null we need to create the layout |
659 if(rowView == null) { | 659 if(rowView == null) { |
660 rowView = ConstraintLayout(context) | 660 rowView = LinearLayout(context) |
661 val set = ConstraintSet() | 661 var lastView: View? = null |
662 var lastID: Int = -1 | 662 |
663 | 663 rowView.orientation = LinearLayout.HORIZONTAL |
664 // Initialize the constraint layout and set | |
665 rowView.id = View.generateViewId() | |
666 set.clone(rowView) | |
667 | 664 |
668 for(i in 0 until displayColumns) { | 665 for(i in 0 until displayColumns) { |
669 val content = model.getRowAndColumn(position, i) | 666 val content = model.getRowAndColumn(position, i) |
670 | 667 |
671 // Image | 668 // Image |
672 if((model.getColumnType(i) and 1) != 0) { | 669 if((model.getColumnType(i) and 1) != 0) { |
673 val imageview = ImageView(context) | 670 val imageview = ImageView(context) |
674 imageview.id = View.generateViewId() | 671 imageview.id = View.generateViewId() |
675 imageview.layoutParams = ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.WRAP_CONTENT, ConstraintLayout.LayoutParams.WRAP_CONTENT) | 672 imageview.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, |
673 LinearLayout.LayoutParams.WRAP_CONTENT) | |
676 if (content is Drawable) { | 674 if (content is Drawable) { |
677 imageview.setImageDrawable(content) | 675 imageview.setImageDrawable(content) |
678 } | 676 } |
679 rowView.addView(imageview) | 677 rowView.addView(imageview) |
680 // Add to the set... | 678 lastView = imageview |
681 if(lastID == -1) { | |
682 set.connect(imageview.id, ConstraintSet.TOP, rowView.id, ConstraintSet.BOTTOM) | |
683 } else { | |
684 set.connect(lastID, ConstraintSet.START, imageview.id, ConstraintSet.END) | |
685 } | |
686 lastID = imageview.id | |
687 } else { | 679 } else { |
688 // Everything else id displayed as text | 680 // Everything else id displayed as text |
689 val textview = TextView(context) | 681 val textview = TextView(context) |
690 textview.id = View.generateViewId() | 682 textview.id = View.generateViewId() |
691 textview.layoutParams = ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.WRAP_CONTENT, ConstraintLayout.LayoutParams.WRAP_CONTENT) | 683 textview.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, |
684 LinearLayout.LayoutParams.WRAP_CONTENT) | |
692 if (content is String) { | 685 if (content is String) { |
693 textview.text = content | 686 textview.text = content |
694 } else if(content is Int) { | 687 } else if(content is Int) { |
695 textview.text = content.toString() | 688 textview.text = content.toString() |
696 } | 689 } |
697 rowView.addView(textview) | 690 rowView.addView(textview) |
698 // Add to the set... | 691 lastView = textview |
699 if(lastID == -1) { | 692 } |
700 set.connect(textview.id, ConstraintSet.TOP, rowView.id, ConstraintSet.BOTTOM) | 693 } |
701 } else { | |
702 set.connect(lastID, ConstraintSet.START, textview.id, ConstraintSet.END) | |
703 } | |
704 lastID = textview.id | |
705 } | |
706 } | |
707 | |
708 // Finally apply the layout | |
709 set.applyTo(rowView) | |
710 | |
711 // TODO: Add code to optionally add other columns | 694 // TODO: Add code to optionally add other columns |
712 } else { | 695 } else { |
713 // Otherwise we just need to update the existing layout | 696 // Otherwise we just need to update the existing layout |
714 | 697 |
715 for(i in 0 until displayColumns) { | 698 for(i in 0 until displayColumns) { |