我有一个ListView,其中每一行都有一个固定的高度.
每行包含一些TextView旁边的行.
有时,我想要显示的文本太大,因此我想使其可滚动.
所以我添加了(基于在Android上可滚动的TextView)以下行到我的TextView
text.setMaxLines(5);
text.setVerticalScrollBarEnabled(true);
text.setMovementMethod(ScrollingMovementMethod.getInstance());
Run Code Online (Sandbox Code Playgroud)
如果我单独使用TextView但是当我将TextView放在ListView中时,这种方法很好:
只要我进行垂直滚动,事件似乎被ListView使用.
关于如何使这项工作的任何建议?
下面添加了完整的(测试)活动(没有layout.xml)
public class TestScrollableTextView extends Activity
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);
//add a ListView
ListView list = new ListView(this);
layout.addView(list);
list.setAdapter(new BaseAdapter()
{
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
TextView text = new TextView(TestScrollableTextView.this);
String s = "";
//add 10 lines of text, all but first are indented
for (int i = 0; i < …Run Code Online (Sandbox Code Playgroud) android textview android-layout android-listview android-scroll
我有一个HorizontalScrollView包含a LinearLayout,其中包含几个FrameLayouts.每个都FrameLayout包含一个的布局Fragment.现在我正在尝试获取视图,即FrameLayout当前可见或焦点在视图内HorizontalScrollView.只要我有焦点的视图,我就可以得到它的索引LinearLayout.
我尝试了以下,但没有任何作用:
FrameLayouts 返回false我还可以LinearLayout通过根据每个孩子的当前X位置进行计算来确定哪个孩子有焦点.但是,呼叫getX()每个孩子总是返回"0.0".
有没有人知道如何获得焦点的视图(甚至更好的是它的索引LinearLayout)?
我有一个自定义列表视图,显示用户,并有照片我从API检索数据,提供JSON输出,
我的问题是列表视图不能平滑滚动,它会挂起一秒钟并滚动,它会重复相同直到我们到达终点.
我认为这可能是因为我在UI线程上运行网络相关操作,但即使在完成加载后它仍然继续这样做?
我的自定义Listview的结构是
<TextView style="@style/photo_post_text"
android:id="@+id/photo_post_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="demotext"
/>
<ImageView
android:id="@+id/userimage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="@drawable/pi"
/>
Run Code Online (Sandbox Code Playgroud) 我有以下情况:
我正在使用导航抽屉让用户轻松地在不同主题之间导航.
你可以在这里找到一张图片:
https://drive.google.com/file/d/0B2gMUEFwlGRfSHRzVlptYmFQTXc/edit?usp=sharing
单击标题时,如General,只使用片段和布局文件替换主内容视图.但是当用户点击子标题(如Gameplay)时,布局会发生变化,并且应该向下滚动到布局中的特定视图.
所以在我的片段类中,我使用的是"onViewCreated"方法和由ScrollView提供的smoothScrollTo方法.ScrollView和RelativeLayout都不为null,并设置为正确的id,在"onCreateView"中设置
Codesnippets:
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (getArguments().getBoolean(ARG_BOOL)) {
scrollView = (ScrollView)getView().findViewById(scrollID);
relativeLayout = (RelativeLayout)getView().findViewById(relativeID);
((ScrollView)getView().findViewById(scrollID)).smoothScrollTo(
0, (getView().findViewById(relativeID)).getLeft());
Toast.makeText(getApplicationContext(), "SCROLL",Toast.LENGTH_SHORT).
show();
}
}
Run Code Online (Sandbox Code Playgroud)
问题是它没有执行"smoothScrollTo"方法,而吐司被执行.
这里我调用片段(布尔滚动用于控制smoothScrollTo方法):
private void selectItem(int Id, boolean scroll) {
Fragment fragment = new ContentFragment();
Bundle args = new Bundle();
args.putBoolean(ContentFragment.ARG_BOOL, scroll);
args.putInt(ContentFragment.ARG_ITEM_ID, Id);
fragment.setArguments(args);
// Insert the fragment by replacing any existing fragment
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment)
.commit();
// …Run Code Online (Sandbox Code Playgroud) 朋友我正在使用listview并在滚动结束时滚动加载内容.但我面临的错误就像同一个url被多次调用一样,如果快速滚动,任何人都可以帮我解决这个问题.我已经走了SCROLL_STATE_IDLE,但不知道如何在我的代码中实现相同的.即使我没有触摸它的运行屏幕.我现在想知道如何在空闲状态下停止代码.在下面找到我的代码
int start = 0;
int limit = 3;
loadingMore = false;
listView.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
int lastInScreen = firstVisibleItem + visibleItemCount;
if ((lastInScreen == totalItemCount) ) {
if(loadingMore == false){
start = lastInScreen - 1;
url = "http://www.dskjhf.com/web-servic/request_response.php?type=get_articles&start="
+ start + "&end=" + limit;
grabURL(url);
}
}}
}); …Run Code Online (Sandbox Code Playgroud) android listview android-listview android-scrollview android-scroll
我正在创建一个旋转木马卧式RecyclerView,其焦点位于从RecyclerView的第一项开始的焦点项上。
自定义CenterZoomLayoutManager的代码:
public class CenterZoomLayoutManager extends LinearLayoutManager {
private final float mShrinkAmount = 0.15f;
private final float mShrinkDistance = 0.9f;
public CenterZoomLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
@Override
public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
int orientation = getOrientation();
if (orientation == HORIZONTAL) {
int scrolled = super.scrollHorizontallyBy(dx, recycler, state);
float midpoint = getWidth() / 2.f;
float d0 = 0.f;
float d1 = mShrinkDistance * midpoint;
float s0 = 1.f;
float s1 = …Run Code Online (Sandbox Code Playgroud) java android android-scroll android-recyclerview linearlayoutmanager
我有一个LinearLayout包含一些其他观点,其中一个ListView.通过单击按钮从另一个视图加载此视图.
此按钮以某种方式指定ListView中的哪个元素需要是列表中第一个可见的元素.填充列表的元素是通过HTTP从外部服务器检索的.
问题是我可以将第N个元素作为列表中的第一个元素.请注意,我不想将其从当前位置移动到新位置,我希望列表滚动.
我曾尝试与setSelected()和scrollTo(x,y)和scrollBy(x,y),但没有运气.
我也尝试过这个代码,虽然它很丑,但我只想尝试f它工作:
ListView categoryList = (ListView)findViewById(R.id.category_list);
categoryList.post(new Runnable() {
@Override
public void run() {
Log.d(this.getClass().getName(), "CategoryActivity.scrollToIndex: " + CategoryActivity.scrollToIndex);
if(CategoryActivity.scrollToIndex>0){
ListView categoryList = (ListView)findViewById(R.id.category_list);
categoryList.setScrollContainer(true);
categoryList.scrollTo(4, CategoryActivity.scrollToIndex * 50);
categoryList.requestLayout();
}
}
});
Run Code Online (Sandbox Code Playgroud)
这给了我一些成功,但ListView当时表现得很疯狂,我甚至无法描述......
任何的想法?
我有一个GridViewin an Activity,我想GridView使用该方法将其滚动到特定位置scrollTo()。具体来说,滚动GridView并在 中scrollTo()提醒 a ,在单击中向后滚动。 DialogOnItemClickListener()scrollTo()PositiveButton
如果我只是单击 中的项目,效果很好,但是如果我在用手指GridView滚动后单击项目,则会滚动到特定位置,然后立即向后滚动。我不知道为什么或如何处理它。GridViewGridView
gv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
gv.scrollTo(0, 200);
AlertDialog.Builder dilog =new AlertDialog.Builder(MainActivity.this);
dilog.setPositiveButton("aa", new OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
gv.scrollTo(0, 0);
}
});
dilog.create().show();
}
});
Run Code Online (Sandbox Code Playgroud) 我想知道在这个问题中有什么方法可以在android中做.我用过ListView并添加了EditText它.我遇到了与上述问题相同的问题.我在android中找不到答案.
谢谢.
我正在开发一款仅在一台运行 KitKat 的设备上运行的 Android 应用程序。
我使用的 RecylerView 的平滑滚动功能在其他物理平板电脑上运行,但 genymotion 不幸的是在它需要运行的一台设备上停止运行。
它不是滚动到某个位置,而是越过目标位置并一直滚动到底部,看起来非常糟糕。
我能够追踪 RecyclerView 类中抽象 SmoothScroller 的错误。
if (getChildPosition(mTargetView) == mTargetPosition) {
onTargetFound(mTargetView, recyclerView.mState, mRecyclingAction);
mRecyclingAction.runIfNecessary(recyclerView);
stop();
} else {
Log.e(TAG, "Passed over target position while smooth scrolling.");
mTargetView = null;
}
Run Code Online (Sandbox Code Playgroud)
我使用的是我在网上找到的 SnappingLinearLayoutManager,但将其换成了 Android 中的普通 LinearLayoutManager,但仍然遇到同样的问题。
该列表有 7 个项目长(用户一次可以看到 4 个项目),我滚动到第 5 个项目(位置 4)。
当我滚动到第三个时,我没有收到此错误。
此外,在我上下滚动列表一次后,错误就停止发生。
编辑: 我可以使用layoutManager.scrollToPositionWithOffset(); 但我正在尝试用平滑的滚动动画来做到这一点。
这是我的一些代码和详细信息:
private void setupMainRecyclerViewWithAdapter() {
mainLayoutManager = new SnappingLinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
mainListRecyclerView.setLayoutManager(mainLayoutManager);
settingsMainListAdapter = new SettingsListAdapter(SettingsActivity.this,
settingsPresenter.getSettingsItems(),
settingsPresenter);
mainListRecyclerView.setAdapter(settingsMainListAdapter);
mainListRecyclerView.addItemDecoration(new BottomOffsetDecoration(EXTRA_VERTICAL_SCROLLING_SPACE)); …Run Code Online (Sandbox Code Playgroud) android android-scroll android-recyclerview linearlayoutmanager