Forum Xamarin.Android

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How to Make CarouselView in Xamarin.Andriod

How to Make CarouselView in Xamarin.Andriod any example refernce

Tagged:

Best Answer

Answers

  • YelinzhYelinzh Member, Xamarin Team Xamurai
    edited June 2020

    @zubair263 Hi, any updates? If the solution helps you to solve the issue, please mark it as the answer. If you are facing some issues while implementing, try to post the particular error with the corresponding codes here.

  • zubair263zubair263 Member ✭✭

    @Jarvan But the Dots not showing over the view.dots hide under the view

  • YelinzhYelinzh Member, Xamarin Team Xamurai
    edited June 2020

    But the Dots not showing over the view.dots hide under the view

    @zubair263 The code works fine on my side, I updated the code on github. Here is a sample link, you could refer to the code.
    https://github.com/yelinzh/Xamarin.Android-CarouselView

  • zubair263zubair263 Member ✭✭


    here is the problemm

  • zubair263zubair263 Member ✭✭

    @Jarvan Please check this screen short

  • YelinzhYelinzh Member, Xamarin Team Xamurai
    edited June 2020

    @zubair263 said:
    @Jarvan Please check this screen short

    How did you config the layout.xml? Could you post the related code?

  • zubair263zubair263 Member ✭✭

    Layout

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:id="@+id/indicator"
            android:layout_alignParentBottom="true"
            android:gravity="center_horizontal"/>
        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentBottom="true"
            android:layout_gravity="center"
            android:textColor="#000"/>
    
    </RelativeLayout>
    

    Layout 1 and same two other layout

        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:minWidth="25px"
            android:paddingTop="10dp"
            android:weightSum="100"
            android:minHeight="25px">
            <ScrollView
                android:minWidth="25px"
                android:minHeight="25px"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/scrollView1">
                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                    <ImageView
                        android:src="@drawable/logo"
                        android:layout_width="match_parent"
                        android:layout_height="60.0dp"
                        android:layout_weight="30"
                        android:id="@+id/imageView1" />
                    <TextView
                        android:id="@+id/lblCreateAccount"
                        android:layout_width="wrap_content"
                        android:inputType="text"
                        android:paddingTop="15dp"
                        android:autoText="true"
                        android:layout_gravity="center_horizontal"
                        android:foregroundGravity="center_vertical"
                        android:layout_height="wrap_content"
                        android:hint="Create a free Account"
                        android:textColor="#ff0c0b0b"
                        android:textSize="16dp"
                        android:paddingBottom="25dp"
                        android:textStyle="bold" />
    
                    <android.support.design.widget.TextInputLayout
                        android:id="@+id/input_layofdsaut_password"
                        android:layout_width="match_parent"
                        android:layout_marginTop="10dp"
                        android:background="@drawable/CustomEntryBackground"
                        android:layout_height="wrap_content">
                        <EditText
                            android:id="@+id/editText3"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:textSize="14dp"
                            android:paddingLeft="5dp"
                            android:hint="Country of Residence"
                            android:gravity="left|top"
                            android:inputType="textMultiLine" >
                        </EditText>
                    </android.support.design.widget.TextInputLayout>
    
                    <android.support.design.widget.TextInputLayout
                        android:id="@+id/input_layofdsaut_password"
                        android:layout_width="match_parent"
                        android:layout_marginTop="10dp"
                        android:background="@drawable/CustomEntryBackground"
                        android:layout_height="wrap_content">
                        <EditText
                            android:id="@+id/editText3"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:textSize="14dp"
                            android:paddingLeft="5dp"
                            android:hint="App Language"
                            android:gravity="left|top"
                            android:inputType="textMultiLine" >
                        </EditText>
                    </android.support.design.widget.TextInputLayout>
    
                    <android.support.design.widget.TextInputLayout
                        android:id="@+id/input_layofdsaut_password"
                        android:layout_width="match_parent"
                        android:layout_marginTop="10dp"
                        android:background="@drawable/CustomEntryBackground"
                        android:layout_height="wrap_content">
                        <EditText
                            android:id="@+id/editText3"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:textSize="14dp"
                            android:paddingLeft="5dp"
                            android:hint="Sex"
                            android:gravity="left|top"
                            android:inputType="textMultiLine" >
                        </EditText>
                    </android.support.design.widget.TextInputLayout>
          <!--          <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="0dip"
                        android:layout_weight="1"
                        android:gravity="center|bottom"
                        android:orientation="vertical">
    
                        <Button
                            android:id="@+id/button1"
                            style="?android:attr/buttonStyleSmall"
                            android:layout_width="145dp"
                            android:backgroundTint="#569ad7"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal|center"
                            android:text="Next" />
    
    
                    </LinearLayout>-->
    
                </LinearLayout>
    
    
            </ScrollView>
        </LinearLayout>
    

    And here is the Activity

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    using Android.App;
    using Android.Content;
    using Android.OS;
    using Android.Runtime;
    using Android.Support.V4.View;
    using Android.Support.V7.App;
    using Android.Views;
    using Android.Widget;
    
    namespace AlgoInvestment
    {
        [Activity(Label = "Create free Account")]
        public class CreateAccountActivity : AppCompatActivity
        {
            private TextView[] _dots { get; set; }
            private LinearLayout _dotsLayout { get; set; }
            protected override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);
                SetContentView(Resource.Layout.layout);
    
                List<Android.Support.V4.App.Fragment> fragments = new List<Android.Support.V4.App.Fragment>();
                fragments.Add(new MyFragment_1());
                fragments.Add(new MyFragment_2());
                fragments.Add(new MyFragment_3());
                fragments.Add(new MyFragment_4());
    
                var adapter = new MyPagerAdapter(SupportFragmentManager, fragments);
                ViewPager pager = (ViewPager)FindViewById(Resource.Id.pager);
                pager.Adapter = adapter;
                pager.PageSelected += Pager_PageSelected;
    
                _dotsLayout = FindViewById<LinearLayout>(Resource.Id.indicator);
                AddDotsIndicator(0);
            }
            private void Pager_PageSelected(object sender, ViewPager.PageSelectedEventArgs e)
            {
                AddDotsIndicator(e.Position);
            }
            private void AddDotsIndicator(int pos)
            {
                _dots = new TextView[4];
                _dotsLayout.RemoveAllViews();
                for (int i = 0; i < _dots.Length; i++)
                {
                    _dots[i] = new TextView(this);
                    _dots[i].Text =  "●";
                    _dots[i].TextSize = 35;
    
                    _dotsLayout.AddView(_dots[i]);
                }
                if (_dots.Length > 0)
                    _dots[pos].SetTextColor(Android.Graphics.Color.Red); //change indicator color on selected page
            }
    
    
        }
    }
    

    @Jarvan

Sign In or Register to comment.