mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
UpdateItemAt
This commit is contained in:
@@ -157,6 +157,16 @@ public class TabLayout extends HorizontalScrollView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the ui of an item at specified index
|
||||||
|
*/
|
||||||
|
public void updateItemAt(int position, TabItemSpec tabItem) {
|
||||||
|
LinearLayout ll = (LinearLayout)mTabStrip.getChildAt(position);
|
||||||
|
ImageView imgView = (ImageView)ll.getChildAt(0);
|
||||||
|
TextView textView = (TextView)ll.getChildAt(1);
|
||||||
|
this.setupItem(ll, textView, imgView, tabItem);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a default view to be used for tabs.
|
* Create a default view to be used for tabs.
|
||||||
*/
|
*/
|
||||||
@@ -172,26 +182,13 @@ public class TabLayout extends HorizontalScrollView {
|
|||||||
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
|
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
|
||||||
ll.setBackgroundResource(outValue.resourceId);
|
ll.setBackgroundResource(outValue.resourceId);
|
||||||
|
|
||||||
ImageView imgView = null;
|
ImageView imgView = new ImageView(context);
|
||||||
if (tabItem.iconId != 0 || tabItem.iconDrawable != null) {
|
|
||||||
imgView = new ImageView(context);
|
|
||||||
imgView.setScaleType(ScaleType.FIT_CENTER);
|
imgView.setScaleType(ScaleType.FIT_CENTER);
|
||||||
LinearLayout.LayoutParams imgLP = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
LinearLayout.LayoutParams imgLP = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
imgLP.gravity = Gravity.CENTER;
|
imgLP.gravity = Gravity.CENTER;
|
||||||
|
|
||||||
imgView.setLayoutParams(imgLP);
|
imgView.setLayoutParams(imgLP);
|
||||||
|
|
||||||
if (tabItem.iconId != 0) {
|
TextView textView = new TextView(context);
|
||||||
imgView.setImageResource(tabItem.iconId);
|
|
||||||
} else {
|
|
||||||
imgView.setImageDrawable(tabItem.iconDrawable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TextView textView = null;
|
|
||||||
if(tabItem.title != null && !tabItem.title.isEmpty()) {
|
|
||||||
textView = new TextView(context);
|
|
||||||
textView.setText(tabItem.title);
|
|
||||||
textView.setGravity(Gravity.CENTER);
|
textView.setGravity(Gravity.CENTER);
|
||||||
textView.setMaxWidth((int) (TEXT_MAX_WIDHT * density));
|
textView.setMaxWidth((int) (TEXT_MAX_WIDHT * density));
|
||||||
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
|
||||||
@@ -201,24 +198,45 @@ public class TabLayout extends HorizontalScrollView {
|
|||||||
textView.setMaxLines(2);
|
textView.setMaxLines(2);
|
||||||
textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||||
textView.setPadding(padding, 0, padding, 0);
|
textView.setPadding(padding, 0, padding, 0);
|
||||||
|
|
||||||
|
this.setupItem(ll, textView, imgView, tabItem);
|
||||||
|
|
||||||
|
ll.addView(imgView);
|
||||||
|
ll.addView(textView);
|
||||||
|
return ll;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(imgView != null && textView!= null){
|
private void setupItem(LinearLayout ll, TextView textView,ImageView imgView, TabItemSpec tabItem){
|
||||||
ll.setMinimumHeight((int) (LARGE_MIN_HEIGHT * density));
|
float density = getResources().getDisplayMetrics().density;
|
||||||
|
|
||||||
|
if (tabItem.iconId != 0) {
|
||||||
|
imgView.setImageResource(tabItem.iconId);
|
||||||
|
imgView.setVisibility(VISIBLE);
|
||||||
|
} else if (tabItem.iconDrawable != null) {
|
||||||
|
imgView.setImageDrawable(tabItem.iconDrawable);
|
||||||
|
imgView.setVisibility(VISIBLE);
|
||||||
|
} else {
|
||||||
|
imgView.setVisibility(GONE);
|
||||||
}
|
}
|
||||||
else{
|
|
||||||
|
if (tabItem.title != null && !tabItem.title.isEmpty()) {
|
||||||
|
textView.setText(tabItem.title);
|
||||||
|
textView.setVisibility(VISIBLE);
|
||||||
|
} else {
|
||||||
|
textView.setVisibility(GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (imgView.getVisibility() == VISIBLE && textView.getVisibility() == VISIBLE) {
|
||||||
|
ll.setMinimumHeight((int) (LARGE_MIN_HEIGHT * density));
|
||||||
|
} else {
|
||||||
ll.setMinimumHeight((int) (SMALL_MIN_HEIGHT * density));
|
ll.setMinimumHeight((int) (SMALL_MIN_HEIGHT * density));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(imgView != null){
|
if (mDistributeEvenly) {
|
||||||
ll.addView(imgView);
|
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ll.getLayoutParams();
|
||||||
|
lp.width = 0;
|
||||||
|
lp.weight = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(textView != null) {
|
|
||||||
ll.addView(textView);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ll;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populateTabStrip() {
|
private void populateTabStrip() {
|
||||||
@@ -231,20 +249,13 @@ public class TabLayout extends HorizontalScrollView {
|
|||||||
TabItemSpec tabItem;
|
TabItemSpec tabItem;
|
||||||
if (this.mTabItems != null && this.mTabItems.length > i) {
|
if (this.mTabItems != null && this.mTabItems.length > i) {
|
||||||
tabItem = this.mTabItems[i];
|
tabItem = this.mTabItems[i];
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
tabItem = new TabItemSpec();
|
tabItem = new TabItemSpec();
|
||||||
tabItem.title = adapter.getPageTitle(i).toString();
|
tabItem.title = adapter.getPageTitle(i).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
tabView = createDefaultTabView(getContext(), tabItem);
|
tabView = createDefaultTabView(getContext(), tabItem);
|
||||||
|
|
||||||
if (mDistributeEvenly) {
|
|
||||||
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
|
|
||||||
lp.width = 0;
|
|
||||||
lp.weight = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
tabView.setOnClickListener(tabClickListener);
|
tabView.setOnClickListener(tabClickListener);
|
||||||
String desc = mContentDescriptions.get(i, null);
|
String desc = mContentDescriptions.get(i, null);
|
||||||
if (desc != null) {
|
if (desc != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user