Ejemplo n.º 1
0
        public void setListViewHeightBasedOnChildren1(ListView listView1)
        {
            reviewAdapter listAdapter = (reviewAdapter)listView1.Adapter;

            if (listAdapter == null)
            {
                return;
            }

            int  desiredWidth      = View.MeasureSpec.MakeMeasureSpec(listView1.Width, MeasureSpecMode.Unspecified);
            int  heightMeasureSpec = View.MeasureSpec.MakeMeasureSpec(ViewGroup.LayoutParams.WrapContent, MeasureSpecMode.Exactly);
            int  totalHeight       = 0;
            View view = null;

            for (int i = 0; i < listAdapter.Count; i++)
            {
                view = listAdapter.GetView(i, view, listView1);
                if (i == 0)
                {
                    view.LayoutParameters = new ViewGroup.LayoutParams(desiredWidth, WindowManagerLayoutParams.WrapContent);
                }

                view.Measure(desiredWidth, heightMeasureSpec);
                totalHeight += view.MeasuredHeight;
            }
            ViewGroup.LayoutParams params1 = listView1.LayoutParameters;
            params1.Height             = totalHeight + (listView1.DividerHeight * (listAdapter.Count - 1));
            listView1.LayoutParameters = params1;
        }
Ejemplo n.º 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.detailedView);

            //Top detailed view
            string[] arr1 = new string[] { "Silver napa valley",
                                           "Cabernet ",
                                           "2011",
                                           " This is the description about wine,This is the description about wine,This is the description about wine" };
            var detailView = FindViewById <ListView>(Resource.Id.listView1);

            DetailsArray = DetailsData();
            DetailsViewAdapter Details = new DetailsViewAdapter(this, DetailsArray);

            detailView.Adapter = Details;

            var commentsView = FindViewById <ListView>(Resource.Id.listView2);

            ReviewArray = ReviewData();
            reviewAdapter comments = new reviewAdapter(this, ReviewArray);

            commentsView.Adapter = comments;


            DetailsArray = DetailsData();
            ReviewArray  = ReviewData();
            setListViewHeightBasedOnChildren(detailView);
            setListViewHeightBasedOnChildren1(commentsView);
            TextView  TopName         = FindViewById <TextView>(Resource.Id.textView6); //Assigning to respected Textfield
            TextView  TopBrand        = FindViewById <TextView>(Resource.Id.textView7);
            TextView  TopVintage      = FindViewById <TextView>(Resource.Id.textView8);
            TextView  WineDescription = FindViewById <TextView>(Resource.Id.textView36);
            TableRow  tr5             = FindViewById <TableRow>(Resource.Id.tableRow5);
            RatingBar rb = FindViewById <RatingBar>(Resource.Id.rating);

            rb.RatingBarChange += Rb_RatingBarChange;
            //String x;
            //rb.RatingBarChange += (o, e) =>
            //{
            //    Toast.MakeText(this, "You have selected " + rb.Rating.ToString() + " Stars", ToastLength.Short).Show();
            //    x = rb.Rating.ToString();
            //};

            var metrics   = Resources.DisplayMetrics;
            var widthInDp = ConvertPixelsToDp(metrics.WidthPixels);
            //var heightInDp = ConvertPixelsToDp(metrics.HeightPixels);
            //ImageView iv = new ImageView(this);
            //iv.LayoutParameters = new LinearLayout.LayoutParams(widthInDp, widthInDp);
            ImageButton ib = FindViewById <ImageButton>(Resource.Id.imageButton1);
            var         pa = ib.LayoutParameters;

            pa.Height = PixelsToDp(widthInDp);
            pa.Width  = PixelsToDp(widthInDp);
            //placeholder.LayoutParameters = new TableRow.LayoutParams(heightInDp, widthInDp);
            //tr5.Layout(0, 0, 100,100 );
            //placeholder.Layout(0, 0, widthInDp, widthInDp);
            //placeholder.LayoutParameters.Width = widthInDp;
            //Java.Lang.ClassCastException: android.widget.TableLayout$LayoutParams cannot be cast to android.widget.TableRow$LayoutParams
            //rb.NumStars = 5;
            //placeholder.Visibility = ViewStates.Visible;
            // iv.SetImageResource(Resource.Drawable.placeholder_bottiglia_lista);
            //tr5.AddView(iv);
            TopName.Focusable         = false;
            TopBrand.Focusable        = false;
            TopVintage.Focusable      = false;
            WineDescription.Focusable = false;


            //placeholder.Focusable = false;
            TopName.Text         = arr1[0]; //Assigning value
            TopBrand.Text        = arr1[1];
            TopVintage.Text      = arr1[2];
            WineDescription.Text = arr1[3];


            BitmapFactory.Options options = new BitmapFactory.Options
            {
                InJustDecodeBounds = false,
                OutHeight          = 75,
                OutWidth           = 75
            };

            // The result will be null because InJustDecodeBounds == true.
            Bitmap result = BitmapFactory.DecodeResource(Resources, Resource.Drawable.placeholder_re, options);

            //placeholder.SetImageBitmap(result);
        }