Android Studio:RecycleView中的项目“跳转”到左侧(Android Studio: Items in RecycleView “jumps” to the left)
我正在处理RecycleView,但我遇到了一些奇怪的事情。 我正在编写一些简单的应用程序,下面是我在RecycleView中自定义行的代码:
<?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="50dp" android:orientation="horizontal"> <LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:orientation="vertical" android:layout_weight="1"> <TextView android:id="@+id/TextViewGameName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="FirstTextView" android:textColor="@android:color/holo_red_dark"/> <TextView android:id="@+id/TextViewPrices" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="SecondTextView" android:textColor="@android:color/holo_blue_dark"/> </LinearLayout> <Button android:id="@+id/ButtonRemove" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="usuń" android:layout_weight="0"> </Button>
但是每当我启动这个应用程序时,出现了一些问题,它看起来像这样:
由于某种原因,按钮跳到左侧,我不知道为什么。 我不会在这里发布除布局以外的任何代码,因为我不认为它与问题本身有任何关系,但如果需要,我可以附加它。 预先感谢您的帮助。
编辑:我的适配器代码:
package com.ja.myboosterproject; import android.content.Context; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; import java.util.List; public class BoosterAdapter extends RecyclerView.Adapter<BoosterAdapter.ViewHolder> { public class ViewHolder extends RecyclerView.ViewHolder{ public TextView gameNameTextView; public TextView pricesTextView; public Button removeButton; public ViewHolder(View itemView) { super(itemView); gameNameTextView = (TextView) itemView.findViewById(R.id.TextViewGameName); pricesTextView = (TextView) itemView.findViewById(R.id.TextViewPrices); removeButton = (Button) itemView.findViewById(R.id.ButtonRemove); } } private List<com.ja.myboosterproject.Booster> mBoosters; private Context mContext; public BoosterAdapter(Context context, List<Booster> boosters){ mContext = context; mBoosters = boosters; } private Context getContext(){ return mContext; } @Override public BoosterAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){ Context context = parent.getContext(); LayoutInflater inflater = LayoutInflater.from(context); View contentView = inflater.inflate(R.layout.booster_list_row, parent, false); ViewHolder viewHolder = new ViewHolder(contentView); return viewHolder; } @Override public void onBindViewHolder(BoosterAdapter.ViewHolder viewHolder, int position){ Booster booster = mBoosters.get(position); viewHolder.gameNameTextView.setText(booster.getGameName()); viewHolder.pricesTextView.setText(booster.getPriceBought() + " - " + booster.getPriceSold()); } @Override public int getItemCount(){ return mBoosters.size(); }
}
I am working on the RecycleView, but I've encountered something weird. I am writing some simple application and here's the code of my custom row in RecycleView:
<?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="50dp" android:orientation="horizontal"> <LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:orientation="vertical" android:layout_weight="1"> <TextView android:id="@+id/TextViewGameName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="FirstTextView" android:textColor="@android:color/holo_red_dark"/> <TextView android:id="@+id/TextViewPrices" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="SecondTextView" android:textColor="@android:color/holo_blue_dark"/> </LinearLayout> <Button android:id="@+id/ButtonRemove" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="usuń" android:layout_weight="0"> </Button>
On the display, it looks quite okay:
But whenever I launch this application, something goes wrong and it looks like this:
Because of some reason, the button jumps to the left side and I have no idea why. I don't post here any piece of code other than layouts because I don't think it's anyhow related to the problem itself, but I can attach it if necessary. Thanks in advance for help.
EDIT: My Adapter code:
package com.ja.myboosterproject; import android.content.Context; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; import java.util.List; public class BoosterAdapter extends RecyclerView.Adapter<BoosterAdapter.ViewHolder> { public class ViewHolder extends RecyclerView.ViewHolder{ public TextView gameNameTextView; public TextView pricesTextView; public Button removeButton; public ViewHolder(View itemView) { super(itemView); gameNameTextView = (TextView) itemView.findViewById(R.id.TextViewGameName); pricesTextView = (TextView) itemView.findViewById(R.id.TextViewPrices); removeButton = (Button) itemView.findViewById(R.id.ButtonRemove); } } private List<com.ja.myboosterproject.Booster> mBoosters; private Context mContext; public BoosterAdapter(Context context, List<Booster> boosters){ mContext = context; mBoosters = boosters; } private Context getContext(){ return mContext; } @Override public BoosterAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){ Context context = parent.getContext(); LayoutInflater inflater = LayoutInflater.from(context); View contentView = inflater.inflate(R.layout.booster_list_row, parent, false); ViewHolder viewHolder = new ViewHolder(contentView); return viewHolder; } @Override public void onBindViewHolder(BoosterAdapter.ViewHolder viewHolder, int position){ Booster booster = mBoosters.get(position); viewHolder.gameNameTextView.setText(booster.getGameName()); viewHolder.pricesTextView.setText(booster.getPriceBought() + " - " + booster.getPriceSold()); } @Override public int getItemCount(){ return mBoosters.size(); }
}
原文:https://stackoverflow.com/questions/48774273
最满意答案
事实证明,数组需要以相反的顺序存储:
Function GetBytes(bi As BigInteger,length As Int32) As Byte() Dim bytes() As Byte = bi.ToByteArray If bytes.Length > length Then Dim result(length - 1) As Byte Array.Copy(bytes,result,length) Array.Reverse(result) Return result Else Array.Reverse(bytes) Return bytes End If End Function
It turns out the arrays need to be stored in reverse order:
Function GetBytes(bi As BigInteger,length As Int32) As Byte() Dim bytes() As Byte = bi.ToByteArray If bytes.Length > length Then Dim result(length - 1) As Byte Array.Copy(bytes,result,length) Array.Reverse(result) Return result Else Array.Reverse(bytes) Return bytes End If End Function
相关问答
更多-
RSACryptoServiceProvider对数据长度有一些假设: 模量:任何均匀的尺寸,我们称之为长度n 指数:( <= 4字节;尽管RSACng允许“任何大小”),我们称长度为e D: n P: n/2 问: n/2 DP: n/2 DQ: n/2 InverseQ: n/2 所以,假设你的第二个键实际上是Modulus:128字节(因为64字节的P乘64字节的Q不是256字节的数字),你只需要将D数组左边填零它达到适当的长度。 byte[] newD = new byte[modulus.Leng ...
-
该查询不支持仅应用程序授权。 这是Twitter的文档: https://dev.twitter.com/rest/reference/get/users/search 相反,您可以使用SingleUserAuthorizer,在此处记录: https://github.com/JoeMayo/LinqToTwitter/wiki/Single-User-Authorization 像这样: var auth = new SingleUserAuthorizer { CredentialStore ...
-
EXC_BAD_ACCESS错误(EXC_BAD_ACCESS Error)[2024-01-31]
我不确定EXC_BAD_ACCESS来自哪里,但是编译器正在将[data objectForKey:@"Location"]作为NSCFString读取,因为NSString是一个类集群,以及其他Foundation类型,如NSNumber和NSArray: 类集群是Foundation框架广泛使用的设计模式。 类集群在公共抽象超类下组合了许多私有的具体子类。 以这种方式对类进行分组简化了面向对象框架的公开可见体系结构,而不会降低其功能丰富性。 类集群基于“可可设计模式”中讨论的抽象工厂设计模式。 最有可能 ... -
DSACryptoServiceProvider.ImportParameters'错误数据'(DSACryptoServiceProvider.ImportParameters 'Bad Data')[2023-04-08]
事实证明,数组需要以相反的顺序存储: Function GetBytes(bi As BigInteger,length As Int32) As Byte() Dim bytes() As Byte = bi.ToByteArray If bytes.Length > length Then Dim result(length - 1) As Byte Array.Copy(bytes,result,length) Array.Reverse(result) Ret ... -
为什么我的Core Data迁移会因EXC_BAD_ACCESS而崩溃(Why is my Core Data migration crashing with EXC_BAD_ACCESS)[2023-06-27]
崩溃的原因是因为映射模型中定义了一些引用最可能的自定义代码的东西,并且代码失败了。 如果您的实体映射不是直截了当的,我建议从该实体映射中删除所有属性映射,然后覆盖: func createDestinationInstances(forSource sInstance: NSManagedObject, in mapping: NSEntityMapping, manager: NSMigrationManager) throws 在哪里准确指定属性应该是什么。 它也可能与这些自定义方法之一有关,它们传 ... -
尝试使用client.PutAsync()而不是client.PutAsJsonAsync() 我会这样称呼它: client.PutAsync("xxx/xx/xxx",new StringContent(myQueueItem, UnicodeEncoding.UTF8, "application/json")).Result Try using client.PutAsync() instead of client.PutAsJsonAsync() I would call it like this ...
-
如果你看看DSA是如何工作的(例如在维基百科上 ),你会发现生成签名的第一步是选择一个随机值: 生成随机的每消息值k,其中0
防止错误的数据输入(Preventing bad data input)[2022-04-19]
在可能的情况下,最好在数据库中指定您的验证规则,并使用或编写一个框架,使这些规则可以鼓舞到您的前端。 ASP.NET动态数据帮助解决这个问题,并且有一些商业库可以让它更容易。 这可以用于简单输入验证(如数字或日期)以及受外键约束的相关数据。 总之,这个想法是在一个地方(数据库大部分时间)定义规则,并在其他层实施这些规则。 It's best to, where possible, have your validation rules specified in your database and use or ...主要是EXC BAD ACCESS(EXC BAD ACCESS in main)[2022-01-09]
就在这里。 在模拟器上使用仪器运行您的应用程序。 选择Zombies乐器并执行使您的应用程序崩溃的确切步骤。 Zombies仪器仅在模拟器上可用,因为Mac上的RAM比iOS设备上的RAM多。 yes there is. Run your app with he instruments ON THE SIMULATOR. Select the Zombies instrument and perform the exact steps that make your app crash. The Zombie ...假设您正在使用BouncyCastle C#1.7,从BigInteger到byte []的转换存在一些问题(与前导零相关)。 这些已在源代码中修复,但尚未发布。 我建议制作最新的DotNetUtilities类的本地副本,并在项目中使用它,直到有新版本可用。 Assuming you are using BouncyCastle C# 1.7, there were some problems with the conversion from BigInteger to byte[] (to do wit ...相关文章
更多- android开发异常汇总
- Memcached stats items 显示各个 slab 中 item 的数目和存储时长
- android 圆角item shape
- Android应用加入微信分享
- android布局问题
- android4.2开发环境搭建
- Android开发学习之快速实现圆角ListView
- EXTJS关于Panel动态ITEMS的问题
- Android开发_微信分享功能
- 我曲折的Android Eclipse开发环境搭建之路
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。