Я пытаюсь реализовать эффект выделения для макета, чтобы помочь ему прокручивать/анимировать с правой внутренней стороны на левую внутреннюю сторону, так же как вид тикера.
Из приведенных ниже двух ссылок вы сможете получить больше знаний, так как фондовые рынки будут обновлять пользователей, показывая значения циклическим постоянным образом.
1) http://www.sify.com/finance/livemarkets/
2) http://terminal.moneycontrol.com/index.php?wl=indices
Для этого я выполнил ниже код, чтобы сделать несколько схожим.
public class HorizonalSlideActivity extends Activity
{
private LinearLayout horizontalOuterLayout;
private HorizontalScrollView horizontalScrollview;
private int scrollMax;
private int scrollPos = 0;
private TimerTask scrollerSchedule;
private Timer scrollTimer = null;
private ScrollAdapter adapter = null;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.horizontal_layout);
adapter = new ScrollAdapter(HorizonalSlideActivity.this);
horizontalScrollview = (HorizontalScrollView) findViewById(R.id.horiztonal_scrollview_id);
horizontalScrollview.setOnTouchListener(new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
return false;
}
});
horizontalOuterLayout = (LinearLayout) findViewById(R.id.horiztonal_outer_layout_id);
horizontalTextView = (TextView) findViewById(R.id.horizontal_textview_id);
horizontalScrollview.setHorizontalScrollBarEnabled(false);
addData();
ViewTreeObserver vto = horizontalOuterLayout.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener()
{
@Override
public void onGlobalLayout()
{
horizontalOuterLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
getScrollMaxAmount();
startAutoScrolling();
}
});
}
private void addData()
{
for (int i = 0; i < adapter.getCount(); i++)
{
View convertView = adapter.getView(i, null, null);
horizontalOuterLayout.addView(convertView);
}
}
public void getScrollMaxAmount()
{
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
Log.e("getScrollMaxAmount", "getWidth == "+width);
Log.e("getScrollMaxAmount", "getMeasuredWidth == "+horizontalOuterLayout.getMeasuredWidth());
int actualWidth = (horizontalOuterLayout.getMeasuredWidth() - width);
Log.e("getScrollMaxAmount", "actualWidth == "+actualWidth);
scrollMax = actualWidth;
Log.e("getScrollMaxAmount", "scrollMax == "+scrollMax);
}
public void startAutoScrolling()
{
if (scrollTimer == null)
{
scrollTimer = new Timer();
final Runnable TimerTick = new Runnable()
{
public void run()
{
moveScrollView();
}
};
if (scrollerSchedule != null)
{
scrollerSchedule.cancel();
scrollerSchedule = null;
}
scrollerSchedule = new TimerTask()
{
@Override
public void run()
{
runOnUiThread(TimerTick);
}
};
scrollTimer.schedule(scrollerSchedule, 3000, 30);
}
}
public void moveScrollView()
{
Log.e("moveScrollView", "scrollMax == "+scrollMax);
scrollPos = (int) (horizontalScrollview.getScrollX() + 1.0);
Log.e("moveScrollView", "scrollPos == "+scrollPos);
if (scrollPos >= scrollMax)
{
scrollPos = 0;
}
horizontalScrollview.scrollTo(scrollPos, 0);
}
public void stopAutoScrolling()
{
if (scrollTimer != null)
{
scrollTimer.cancel();
scrollTimer = null;
}
}
public void onBackPressed()
{
super.onBackPressed();
finish();
}
public void onPause()
{
super.onPause();
finish();
}
public void onDestroy()
{
clearTimerTaks(scrollerSchedule);
clearTimers(scrollTimer);
scrollerSchedule = null;
scrollTimer = null;
super.onDestroy();
}
private void clearTimers(Timer timer)
{
if (timer != null)
{
timer.cancel();
timer = null;
}
}
private void clearTimerTaks(TimerTask timerTask)
{
if (timerTask != null)
{
timerTask.cancel();
timerTask = null;
}
}
}
Вот макет для этого файла:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:id="@+id/horiztonal_scrollview_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fadingEdge="none" >
<LinearLayout
android:id="@+id/horiztonal_outer_layout_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="5dip"
android:paddingTop="5dip" >
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
Класс адаптера для отображения данных:
public class ScrollAdapter extends BaseAdapter
{
private Context context;
public ScrollAdapter(Context context)
{
this.context = context;
}
@Override
public int getCount()
{
return 10;
}
@Override
public Object getItem(int position)
{
return position;
}
@Override
public long getItemId(int position)
{
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
convertView = inflater.inflate(R.layout.scroll_child, null);
return convertView;
}
}
И его xml файл:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/txtPercent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:text="0.14%" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@android:color/white" />
<TextView
android:id="@+id/txtData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:text="data" />
</LinearLayout>
Используя это, я несколько приблизился, но не смог сделать желаемого. Пожалуйста, помогите мне сделать его круговым без прерывания и перезапустить прокрутку после того, как последние данные перемещаются внутри с левой стороны.
Вот желаемый результат:
Также я проверил эту ссылку, он дает эффект прокрутки, что нужно, но не отображает все данные, его показы только 3 4, но, как вы видите, я добавил 10 данных в класс адаптера.
Любая помощь будет заметна.
Спасибо заранее.