我正在尝试对布局实现选框效果,以帮助它从右侧内侧滚动/动画到左侧内侧,就像股票代码 View 一样。
通过以下两个链接,您将能够获得更多的知识,就像股市通过以循环恒定的方式显示值(value)来让用户保持更新一样。
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>
通过实现这一点,我有点接近但无法做出想要的东西。请帮我让它在没有任何中断的情况下循环并在最后一个数据从左侧移入后重新开始滚动。
这是想要的结果:
我也检查了this link ,它提供了所需的滚动效果,但不显示整个数据,它只显示 3 到 4 个 View ,但正如您所见,我在适配器类中添加了 10 个数据。
任何形式的帮助都将是可观的。
提前致谢。
最佳答案
可以使用 Recycleview 和 autoscroll runnable 来完成。 在此处添加代码 fragment
1. MainActivity (MarqueeViewSample.java)
package com.test.mo.test;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
/**
* Created by jovin.pj on 29-07-2015.
*/
public class MarqueeViewSample extends Activity {
private final Runnable SCROLLING_RUNNABLE = new Runnable() {
@Override
public void run() {
final int duration = 10;
final int pixelsToMove = 10;
marqueList.smoothScrollBy(pixelsToMove, 0);
mHandler.postDelayed(this, duration);
}
};
private final Handler mHandler = new Handler(Looper.getMainLooper());
private RecyclerView marqueList;
//private boolean loading = true;
private boolean foundTotalPixel = true;
private int pastVisiblesItems, visibleItemCount, totalItemCount;
private int totalMovedPixel;
private int totalPixel;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
marqueList = (RecyclerView) findViewById(R.id.marqueList);
final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
marqueList.setLayoutManager(layoutManager);
marqueList.setAdapter(new ScrollAdapter());
marqueList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
totalMovedPixel = totalMovedPixel + dx;
visibleItemCount = layoutManager.getChildCount();
totalItemCount = layoutManager.getItemCount();
pastVisiblesItems = layoutManager.findFirstVisibleItemPosition();
if (foundTotalPixel) {
if (totalItemCount > 2) {
View headerView = layoutManager.getChildAt(0);
View itemView = layoutManager.getChildAt(1);
if (itemView != null && headerView != null) {
/*total visible scrolling part is total pixel's of total item's count and header view*/
totalPixel = /*-c.getTop() +*/ ((totalItemCount - 2) * itemView.getWidth()) + (1 * headerView.getWidth());
Log.v("...", "Total pixel x!" + totalPixel);
foundTotalPixel = false;
}
}
}
//if (loading) {
//if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
if (!foundTotalPixel && totalMovedPixel >= totalPixel) {
// loading = false;
Log.v("...", "Last Item Wow !");
Log.v("...", "totalMovedPixel !" + totalMovedPixel);
// use this to turn auto-scrolling off:
//mHandler.removeCallbacks(SCROLLING_RUNNABLE);
marqueList.setAdapter(null);
marqueList.setAdapter(new ScrollAdapter());
pastVisiblesItems = visibleItemCount = totalItemCount = 0;
totalMovedPixel = 0;
}
}
// }
});
// use this to turn auto-scrolling on:
mHandler.post(SCROLLING_RUNNABLE);
}
}
<强>2。 SampleAdapter(ScrollAdapter.java)
package com.test.mo.test;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
/**
* Created by jovin.pj on 29-07-2015.
*/
public class ScrollAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int TYPE_HEADER = 0;
private static final int TYPE_ITEM = 1;
private static final int TYPE_FOOTER = 2;
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
RecyclerView.ViewHolder viewHolder = null;
if (viewType == TYPE_ITEM) {
//inflate your layout and pass it to view holder
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.scroll_child, parent, false);
viewHolder = new ViewHolderItem(view);
} else if (viewType == TYPE_HEADER || viewType == TYPE_FOOTER) {
//inflate your layout and pass it to view holder
//View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.header_footer, parent, false);
View view = new View(parent.getContext());
DisplayMetrics metrics = parent.getContext().getResources().getDisplayMetrics();
int width = metrics.widthPixels;
view.setLayoutParams(new LinearLayout.LayoutParams(width, LinearLayout.LayoutParams.WRAP_CONTENT));
viewHolder = new ViewHolderHeaderOrFooter(view);
}
return viewHolder;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
}
@Override
public int getItemCount() {
// 1 for header and 1 for footer
return 4 + 1 + 1;
}
@Override
public int getItemViewType(int position) {
if (isPositionHeader(position))
return TYPE_HEADER;
else if (isPositionFooter(position))
return TYPE_FOOTER;
return TYPE_ITEM;
}
private boolean isPositionHeader(int position) {
return position == 0;
}
private boolean isPositionFooter(int position) {
return position == getItemCount() - 1;
}
// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
public static class ViewHolderItem extends RecyclerView.ViewHolder {
// each data item is just a string in this case
public View mView;
public ViewHolderItem(View v) {
super(v);
mView = v;
}
}
// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
public static class ViewHolderHeaderOrFooter extends RecyclerView.ViewHolder {
// each data item is just a string in this case
public View mView;
public ViewHolderHeaderOrFooter(View v) {
super(v);
mView = v;
}
}
}
3. Main Activity 的布局文件(main.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/marqueList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:clipToPadding="false" />
</LinearLayout>
4.适配器的布局文件(scroll_child.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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/darker_gray" />
<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>
增加或减少pixelsToMove,这个变量值改变速度
关于android - 线性布局的选框效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31471552/
是否可以为特定(或所有)项目使用多个布局?例如,我有几个项目,我想对其应用两种不同的布局。一个是绿色的,一个是蓝色的(但是)。我想将它们编译到我的输出目录中的两个不同文件夹中(例如v1和v2)。我一直在玩弄规则和编译block,但我不知道这是怎么回事。因为,每个项目在编译过程中只编译一次,我不能告诉nanoc第一次用layout1编译,第二次用layout2编译。我试过这样的东西,但它导致输出文件损坏。compile'*'doifitem.binary?#don’tfilterbinaryitemselsefilter:erblayout'layout1'layout'layout2'
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
我有以下不起作用的代码:=form_for(resource,:as=>resource_name,:url=>session_path(resource_name),:html=>{:class=>"well"})do|f|=f.label:email=f.email_field:email=f.label:password=f.password_field:password-ifdevise_mapping.rememberable?%p=f.label:remember_me,:class=>"checkbox"=f.check_box:remember_me,:class=>"
我正在尝试以嵌套形式实现HABTM复选框。目前,我有3个模型。主题、类(class)和小组。协会如下:每个科目都有很多课。每节课都属于许多小组。现在,我正在尝试在单个创建和编辑表单上实现它们。这样一节课嵌套在主题中,每节课都有一个组复选框列表来实现HABTM关系。我在实现HABTM关系时遇到了麻烦,因为每个科目都有很多类(class),而且我不确定如何区分不同的类(class)。为了进一步详细说明,我能够使嵌套表单正常工作,但我无法让HABTM复选框保存到正确的类(class)中。以下代码示例是我的HABTM复选框实现。目前,我已经使用“subject[lessons_attribut
ruby调试器不会在我在与执行开始时不同的文件中设置的断点处停止。例如,考虑这两个文件,foo.rb:#foo.rbclassFoodefbarputs"baz"endend和main.rb:#main.rbrequire'./foo'Foo.new.bar我使用ruby-rdebug.\main.rb开始调试。现在,当我尝试使用b./foo.rb:4在另一个文件的特定行上设置断点时,我收到消息Setbreakpoint1atfoo.rb:4,但是当我cont时,程序执行到最后,调试器永远不会停止。但是,如果我在main.rb中的一行上打断,例如b./main.rb:3,或者一个方法,
今天我在我的Rails控制台中尝试了一些东西,这发生了,2.0.0p247:009>Date.today-29.days=>Fri,07Feb20142.0.0p247:010>Date.today-29.days=>Thu,09Jan2014我很困惑。我可以看到我缺少一些基本的东西。但这让我印象深刻!谁能解释为什么会这样? 最佳答案 实际发生的是这样的:Date.today(-29.days)#=>Fri,07Feb2014today有一个名为start的可选参数,默认为Date::ITALY。Anoptionalargument
视频教程:https://www.bilibili.com/video/BV1WJ411778C/?spm_id_from=333.999.0.0&vd_source=4a4c35da6aef7094d5990c213c39aa09使用素材(推荐使用GitZipforgithub下载):https://github.com/zheyuanzhou/Youtube-Unity-Tutorial/tree/master/EP45_Health%20Bar/Sprites效果如下图所示:首先在场景中创建一个新的Canvas,并命名为HeathBar,并创建三个Image作为前者的子物体,分别命名为
我想为网站的管理和公共(public)部分设置一对样式指南。每个都需要自己的布局,其中包含静态html和调用erbpartials的混合(因此静态页面不会削减它)。我不需要Controller来为这些页面提供服务,而且我不希望有效的仅开发内容使其余代码困惑。这让我想知道是否有一种方法可以直接呈现布局。免责声明:我明白这不是我应该经常/永远做的事情,而且我知道有很多争论可以解释为什么这是一个坏主意。我对这是否可能感兴趣。有没有办法让我直接从routes.rb渲染布局而不通过Controller? 最佳答案 出于某种奇怪的原因,我想暂时
这个问题在这里已经有了答案:differentlayoutforsign_inactionindevise(8个答案)关闭7年前。如何更改设计Controller中的布局?
AB我在我的代码中使用了上面提到的,当我点击提交时,如果checked则需要1,如果没有,则需要0检查并将其存储在db中。如果checked我如何存储一个string像AB和nil如果notchecked我想将该字符串存储在db而不是0和1中? 最佳答案 这是这个辅助方法的定义:check_box(object_name,method,options={},checked_value="1",unchecked_value="0")所以我想你需要这样的东西:AB但在您的Rails应用程序中,您会得到字符串'AB'和字符串'nil',