是否允许用户拖放 ActionBar 中的导航标签, 以便重新订购它们到 Android 4. 0 ICS 上? 我指的不是在已折旧的 TabHost 中的标签, 而是在 Honeycomb 及以上使用的 ActionBar 中添加的标签 。
谢谢!
是否允许用户拖放 ActionBar 中的导航标签, 以便重新订购它们到 Android 4. 0 ICS 上? 我指的不是在已折旧的 TabHost 中的标签, 而是在 Honeycomb 及以上使用的 ActionBar 中添加的标签 。
谢谢!
使用 < a href=> https://github.com/android/platform_frameworks_base_base/blob/master/core/java/android/app/ActionBar.java" rel=“nofolt”\\code >ActionBar.Tabs 时,他们根本就没有实现这一点的功能。另一方面,建立模仿 Tabs
的自定义类已经足够容易,那么你要做的就是创建和添加 OnDragListlemer
和
例如,这是我的一个应用程序中使用的类,它模仿了 ActionBar.Tabs
。
< 强 > 滚动塔布View 强 >
public class ScrollableTabView extends HorizontalScrollView implements OnPageChangeListener {
private final Context mContext;
private final LinearLayout mContainer;
private final ArrayList<View> mTabs = new ArrayList<View>();
private final int mDividerColor = 0xFF636363;
private int mDividerMarginTop = 12;
private int mDividerMarginBottom = 12;
private int mDividerWidth = 1;
private ViewPager mPager;
private TabAdapter mAdapter;
private Drawable mDividerDrawable;
public ScrollableTabView(Context context) {
this(context, null);
}
public ScrollableTabView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public ScrollableTabView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs);
mContext = context;
final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
android.view.ViewGroup.LayoutParams.MATCH_PARENT,
android.view.ViewGroup.LayoutParams.MATCH_PARENT);
mDividerMarginTop = (int)(getResources().getDisplayMetrics().density * mDividerMarginTop);
mDividerMarginBottom = (int)(getResources().getDisplayMetrics().density * mDividerMarginBottom);
mDividerWidth = (int)(getResources().getDisplayMetrics().density * mDividerWidth);
setHorizontalScrollBarEnabled(false);
setHorizontalFadingEdgeEnabled(false);
mContainer = new LinearLayout(context);
mContainer.setOrientation(LinearLayout.HORIZONTAL);
mContainer.setLayoutParams(params);
addView(mContainer);
}
/**
* Set the tabs Adapter
*
* @param adapter
*/
public void setAdapter(TabAdapter adapter) {
mAdapter = adapter;
if (mPager != null && mAdapter != null) {
initTabs();
}
}
/**
* Attach ViewPager
*
* @param pager
*/
public void setViewPager(ViewPager pager) {
mPager = pager;
mPager.setOnPageChangeListener(this);
if (mPager != null && mAdapter != null) {
initTabs();
}
}
/**
* Initiate the tabs
*/
private void initTabs() {
mContainer.removeAllViews();
mTabs.clear();
if (mAdapter == null) {
return;
}
for (int i = 0; i < mPager.getAdapter().getCount(); i++) {
final int index = i;
final View tab = mAdapter.getView(i);
mContainer.addView(tab);
tab.setFocusable(true);
mTabs.add(tab);
if (i != mPager.getAdapter().getCount() - 1) {
mContainer.addView(getSeparator());
}
tab.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mPager.getCurrentItem() == index) {
selectTab(index);
} else {
mPager.setCurrentItem(index, true);
}
}
});
}
selectTab(mPager.getCurrentItem());
}
@Override
public void onPageScrollStateChanged(int state) {
// Nothing to do
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
// Nothing to do
}
@Override
public void onPageSelected(int position) {
selectTab(position);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
if (changed) {
selectTab(mPager.getCurrentItem());
}
}
/**
* @return Separates the tabs
*/
private View getSeparator() {
final View v = new View(mContext);
final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(mDividerWidth,
android.view.ViewGroup.LayoutParams.MATCH_PARENT);
params.setMargins(0, mDividerMarginTop, 0, mDividerMarginBottom);
v.setLayoutParams(params);
if (mDividerDrawable != null) {
v.setBackground(mDividerDrawable);
} else {
v.setBackgroundColor(mDividerColor);
}
return v;
}
/**
* @param position
*/
private void selectTab(int position) {
for (int i = 0, pos = 0; i < mContainer.getChildCount(); i += 2, pos++) {
final View tab = mContainer.getChildAt(i);
tab.setSelected(pos == position);
}
final View selectedTab = mContainer.getChildAt(position * 2);
final int w = selectedTab.getMeasuredWidth();
final int l = selectedTab.getLeft();
final int x = l - this.getWidth() / 2 + w / 2;
smoothScrollTo(x, this.getScrollY());
}
}
< 强度 > TabAdapter < /强 >
public interface TabAdapter {
public View getView(int position);
}
< 强势 > 附加您的 TabAdapter 强 >
public class ScrollingTabsAdapter implements TabAdapter {
private final FragmentActivity activity;
private final LayoutInflater inflater;
private Button mTabs;
// Tab titles
private static final String[] mTitles = {
"RECENT", "ARTISTS", "ALBUMS", "SONGS", "PLAYLISTS", "GENRES"
};
/**
* @param act
*/
public ScrollingTabsAdapter(FragmentActivity act) {
activity = act;
inflater = activity.getLayoutInflater();
}
@Override
public View getView(int position) {
mTabs = (Button)inflater.inflate(R.layout.tabs, null);
if (position < mTitles.length) {
mTabs.setText(mTitles[position]);
}
return mTabs;
}
}
您可以使用真实 ActionBar.Tabs
的默认绘图和属性来给您充气。 您可以从 SDK 或网络上某个地方抓取它们。 要使用它, 请在 标上附加一个
ViewPager
, 并在 StabView
中添加每个 fractionments
, 在 FraggmentPagerAdapter
中键入样式。 < a href=" https://i. statistic. net/7GCFz.png" rel=" no folpol " 这就是它们看起来的样子, 如果您在添加默认绘图和属性 之后对样式表示好奇的话, 。
就拖拉和拖放而言,Android在其网站上有一些不错的文档。Drag和drug
在网上也有一些容易学习的教程。 Android Drag and Drop Tourment,通过Lars Vogel 。
< a href=" "https://www.google.com/search? sugfem=chrome,mod=12&sourceid=chrome&ie=UTF-8&q=drag+and+drop+view+view+android&qscrl=1, rel=“nolfol” > 或者您可以简单地使用 Google 查找更多
I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...
I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...
I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...
I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...
To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?
When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...
I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...
I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...