Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

line in the end is not straight when i changes view size #6

Open
honeykapoor7 opened this issue Jun 25, 2020 · 0 comments
Open

line in the end is not straight when i changes view size #6

honeykapoor7 opened this issue Jun 25, 2020 · 0 comments

Comments

@honeykapoor7
Copy link

My Main activity

:-
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Arrays;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.res.ResourcesCompat;
import io.itimetraveler.widget.adapter.PickerAdapter;
import io.itimetraveler.widget.model.StringItemView;
import io.itimetraveler.widget.picker.PicketOptions;
import io.itimetraveler.widget.picker.WheelPicker;

public class MainActivity extends AppCompatActivity {
public static Context context;
Button button, button2;
WheelPicker mWheelPicker;
String selectedstr = null;
Typeface tf;
View v;
@OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this;
v = findViewById(R.id.header_Layout);
button = findViewById(R.id.button);
button2 = findViewById(R.id.button2);
tf = ResourcesCompat.getFont(MainActivity.this, R.font.opensansbold);
mWheelPicker = (WheelPicker) findViewById(R.id.wheel_picker);
final List mList = Arrays.asList("10:10 AM", "10:12 AM", "10:14 AM", "10:16 AM", "10:18 AM", "10:10 AM", "10:12 AM", "10:14 AM", "10:16 AM", "10:18 AM", "10:10 AM", "10:12 AM", "10:14 AM", "10:16 AM", "10:18 AM", "10:10 AM", "10:12 AM", "10:14 AM", "10:16 AM", "10:18 AM", "10:10 AM", "10:12 AM", "10:14 AM", "10:16 AM", "10:18 AM", "10:10 AM", "10:12 AM", "10:14 AM", "10:16 AM", "10:18 AM");

    mWheelPicker.setActivated(true);
    mWheelPicker.setOptions(new PicketOptions.Builder()
            .linkage(true)
            .dividedEqually(true)
            .dividerColor(Color.parseColor("#000000"))
            .build());
    mWheelPicker.setVisibility(View.GONE);
    PickerAdapter adapter = new PickerAdapter() {
        @Override
        public int numberOfComponentsInWheelPicker(WheelPicker wheelPicker) {
            return 1;
        }

        @Override
        public int numberOfRowsInComponent(int component) {
            switch (component) {
                case 0:
                    return mList.size();
            }
            return 0;
        }

        @Override
        public View onCreateView(ViewGroup parent, int row, int component) {
            String str = "";
            switch (component) {
                case 0:
                    str = mList.get(row);
                    break;
            }

// if (parent.getChildAt(row) instanceof TextView) {
// TextView tab = (TextView) parent.getChildAt(row);
// int tabTypefaceStyle = Typeface.BOLD;
// tab.setTypeface(tf, tabTypefaceStyle);
// tab.setTextColor(Color.parseColor("#123fee"));
// }
return new StrItemView(String.valueOf(str)).onCreateView(parent);
}

        @Override
        public void onBindView(ViewGroup parent, View convertView, int row, int component) {
            String str = "";
            switch (component) {
                case 0:
                    str = mList.get(row);
                    break;
            }
            if (parent.getChildAt(row) instanceof TextView) {
                TextView tab = (TextView) parent.getChildAt(row);
                int tabTypefaceStyle = Typeface.BOLD;

                tab.setTypeface(ResourcesCompat.getFont(parent.getContext(), R.font.montserrat_medium));

                tab.setTextColor(Color.parseColor("#123fee"));
            }
            if (convertView instanceof TextView) {
                TextView tab = (TextView) convertView;
                int tabTypefaceStyle = Typeface.BOLD;
                tab.setTypeface(ResourcesCompat.getFont(parent.getContext(), R.font.montserrat_medium));
                tab.setTextColor(Color.parseColor("#123fee"));
            }
            new StrItemView(String.valueOf(str)).onBindView(parent, convertView, row);
        }
    };


    mWheelPicker.setAdapter(adapter);
    mWheelPicker.setOnItemSelectedListener(new WheelPicker.OnItemSelectedListener() {
        @Override
        public void onItemSelected(WheelPicker parentView, int[] position) {
            selectedstr = mList.get(position[0]);
            Toast.makeText(MainActivity.context, selectedstr, Toast.LENGTH_LONG).show();

        }
    });
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // demo dateset
            Animation slideUp = AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_up);
            v.setVisibility(View.VISIBLE);
            button2.setVisibility(View.VISIBLE);
            mWheelPicker.setVisibility(View.VISIBLE);
            v.startAnimation(slideUp);


        }
    });
    button2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (selectedstr == null) {
                selectedstr = mList.get(0);
            }
            Animation slidedown = AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_down);

// Toast.makeText(MainActivity.context, selectedstr, Toast.LENGTH_LONG).show();

            v.startAnimation(slidedown);
            button2.setVisibility(View.GONE);
            mWheelPicker.setVisibility(View.GONE);

        }
    });
}

}

stringitemView Class 👎

import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

import androidx.core.content.res.ResourcesCompat;
import io.itimetraveler.widget.model.BasePickerItemView;
import io.itimetraveler.widget.picker.PicketOptions;
import io.itimetraveler.widget.view.AutoFitTextView;

/**

  • Created by iTimeTraveler on 2018/9/14.
    */
    public class StrItemView extends BasePickerItemView {

    public StrItemView(String data) {
    super(data);
    this.data = data;
    }

    @OverRide
    public View onCreateView(ViewGroup parent) {
    LinearLayout v = new LinearLayout(parent.getContext());
    Button b = new Button(parent.getContext());
    b.setText("mmm");

     AutoFitTextView tv = new AutoFitTextView(parent.getContext());
     tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
             ViewGroup.LayoutParams.WRAP_CONTENT));
     tv.setPadding(20, 3, 20, 3);
     tv.setTextSize(20);
     int[] colors = new int[] {PicketOptions.SELECTED_TEXT_COLOR, PicketOptions.DEFAULT_TEXT_COLOR};
     int[][] states = {{android.R.attr.state_selected}, {}};
     tv.setTextColor(new ColorStateList(states, colors));
     tv.setTypeface(ResourcesCompat.getFont(parent.getContext(), R.font.montserrat_medium));
    

// tv.setTypeface(ResourcesCompat.getFont(parent.getContext(), R.font.));
tv.setTextColor(new ColorStateList(states, colors));
tv.setText(data, parent.getMeasuredWidth());
return tv;

}

@Override
public void onBindView(ViewGroup parent, View view, int position) {


    if (view instanceof AutoFitTextView) {
        AutoFitTextView tv = new AutoFitTextView(parent.getContext());
        tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        tv.setPadding(20, 3, 20, 3);
        tv.setTextSize(20);
        int[] colors = new int[] {PicketOptions.SELECTED_TEXT_COLOR, PicketOptions.DEFAULT_TEXT_COLOR};
        int[][] states = {{android.R.attr.state_selected}, {}};
        tv.setTextColor(new ColorStateList(states, colors));
        tv.setTypeface(ResourcesCompat.getFont(parent.getContext(), R.font.montserrat_medium));

// tv.setTypeface(ResourcesCompat.getFont(parent.getContext(), R.font.));
tv.setTextColor(new ColorStateList(states, colors));
tv.setText(data, parent.getMeasuredWidth());
}

}

@Override
public String toString() {
    return "StringItemView{" +
            ", data='" + data + '\'' +
            '}';
}

}

When I changes the tv.setTextSize(20); from 20 to more or less line does not ends up straight

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant