Last active
August 1, 2018 10:39
-
-
Save SouravKumarPandit/3a084d9d51018f9f25b61e235d1049fb to your computer and use it in GitHub Desktop.
for who want to use the textinputlayout in the spinner use this relative layout and pass the spinner or any view in this or show dilog for picking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.focus.centra.crm.ui.view.list.util; | |
import android.animation.Animator; | |
import android.annotation.SuppressLint; | |
import android.content.Context; | |
import android.text.TextUtils; | |
import android.util.TypedValue; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ImageView; | |
import android.widget.RelativeLayout; | |
import android.widget.TextView; | |
import com.focus.centra.crm.R; | |
@SuppressLint("ViewConstructor") | |
public class CLLabelledView extends RelativeLayout | |
{ | |
private ImageView bottomLine; | |
private TextView textLabel; | |
boolean bSelected = false; | |
boolean hasContent; | |
public CLLabelledView(Context context, View view) | |
{ | |
super(context); | |
// this.setPadding(8, 10, 4, 0); | |
// this.setLayoutParams(new ViewGroup.LayoutParams(view.getWidth(), ViewGroup.LayoutParams.WRAP_CONTENT)); | |
textLabel = new TextView(context); | |
textLabel.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); | |
textLabel.setText("Select"); | |
textLabel.setSingleLine(true); | |
RelativeLayout.LayoutParams labelParam = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); | |
labelParam.addRule(RelativeLayout.CENTER_VERTICAL); | |
labelParam.addRule(RelativeLayout.ALIGN_PARENT_LEFT); | |
textLabel.setLayoutParams(labelParam); | |
textLabel.setEllipsize(TextUtils.TruncateAt.MARQUEE); | |
textLabel.setTextAlignment(View.TEXT_ALIGNMENT_INHERIT); | |
bottomLine = new ImageView(context); | |
RelativeLayout.LayoutParams bottomLineParam = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1); | |
bottomLineParam.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); | |
bottomLine.setLayoutParams(bottomLineParam); | |
bottomLine.setBackgroundColor(getResources().getColor(R.color.gray_500)); | |
// textLabel.setTextColor(CLThemeUtil.getThemeAssetColor(context)); | |
RelativeLayout.LayoutParams viewParam = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); | |
viewParam.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); | |
viewParam.addRule(RelativeLayout.ALIGN_PARENT_LEFT); | |
view.setLayoutParams(viewParam); | |
this.addView(textLabel); | |
this.addView(view); | |
this.addView(bottomLine); | |
view.setVisibility(VISIBLE); | |
bottomLine.setVisibility(INVISIBLE); | |
// if (hasContent==false) | |
setTextCollapsed(context, textLabel, view, bottomLine); | |
} | |
public TextView getTextLabel() | |
{ | |
return textLabel; | |
} | |
public TextView setTextLabelCollapsed(boolean bSelected) | |
{ | |
this.bSelected = bSelected; | |
hasContent = bSelected; | |
return textLabel; | |
} | |
public boolean isHasContent() | |
{ | |
return hasContent; | |
} | |
public void setHasContent(boolean hasContent) | |
{ | |
this.hasContent = hasContent; | |
} | |
public void setLabel(String label) | |
{ | |
if (label != null && !label.equals("")) | |
textLabel.setText(label); | |
} | |
private void setTextCollapsed(final Context context, final TextView textLabel, final View otherView, final View bottomLine) | |
{ | |
textLabel.setOnClickListener(new OnClickListener() | |
{ | |
@Override | |
public void onClick(View view) | |
{ | |
// if (!isFirst) { | |
textLabel.clearAnimation(); | |
if (bSelected) | |
{ | |
// textLabel.setTextColor(CLThemeUtil.getToolbarColor(context)); | |
textLabel.animate().scaleY(0.7f).scaleX(0.7f).translationY(-textLabel.getHeight() * 0.7f).translationX(-textLabel.getWidth() / 7).setDuration(200) | |
.setListener(new Animator.AnimatorListener() | |
{ | |
@Override | |
public void onAnimationStart(Animator animator) | |
{ | |
} | |
@Override | |
public void onAnimationEnd(Animator animator) | |
{ | |
if (!hasContent) | |
otherView.performClick(); | |
} | |
@Override | |
public void onAnimationCancel(Animator animator) | |
{ | |
} | |
@Override | |
public void onAnimationRepeat(Animator animator) | |
{ | |
} | |
}); | |
otherView.setVisibility(VISIBLE); | |
bottomLine.setVisibility(INVISIBLE); | |
bSelected = false; | |
} | |
else | |
{ | |
// textLabel.setTextColor(CLThemeUtil.getThemeAssetColor(context)); | |
otherView.setVisibility(INVISIBLE); | |
bottomLine.setVisibility(VISIBLE); | |
textLabel.animate().scaleY(1f).scaleX(1f).translationY(0).translationX(0).setListener(null); | |
bSelected = true; | |
} | |
/*} else { | |
isFirst = false; | |
otherView.setVisibility(INVISIBLE); | |
}*/ | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
then use in spinner like this
adapter listener .