Android ListView需要两个手指才能滚动
我有一个非常简单的布局,我打算在片段中使用它进行基本聊天,但是在ListView中滚动需要我将一个手指放在ListView中某个项目的屏幕上,然后用另一个手指向上或向下滚动。我的印象是ListView应该只需要一个手指/触摸就能滚动。在我的布局、适配器中,甚至在我用来填充适配器的代码中,是否有我忽略的东西 聊天室布局XMLAndroid ListView需要两个手指才能滚动,android,android-layout,listview,Android,Android Layout,Listview,我有一个非常简单的布局,我打算在片段中使用它进行基本聊天,但是在ListView中滚动需要我将一个手指放在ListView中某个项目的屏幕上,然后用另一个手指向上或向下滚动。我的印象是ListView应该只需要一个手指/触摸就能滚动。在我的布局、适配器中,甚至在我用来填充适配器的代码中,是否有我忽略的东西 聊天室布局XML <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" andro
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF" >
<ListView
android:id="@+id/msgListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/form"
android:divider="@null"
android:dividerHeight="0dp"
android:scrollbarSize="3dp"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical"
android:scrollingCache="true"
android:smoothScrollbar="true"
android:paddingBottom="10dp" />
<LinearLayout
android:id="@+id/form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="@color/primary"
android:orientation="horizontal"
android:paddingBottom="2dp" >
<EditText
android:id="@+id/messageEditText"
android:layout_width="252dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/button1"
android:layout_toLeftOf="@+id/sendMessageButton"
android:layout_weight="0.72"
android:ems="10"
android:maxHeight="80dp" />
<ImageButton
android:id="@+id/sendMessageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@drawable/chat_send_button" />
</LinearLayout>
</RelativeLayout>
列表视图适配器
public class ChatMessageAdapter extends BaseAdapter {
private static LayoutInflater inflater = null;
ArrayList<ChatMessage> chatMessageList;
public ChatMessageAdapter(Activity activity, ArrayList<ChatMessage> list) {
chatMessageList = list;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return chatMessageList.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ChatMessage message = chatMessageList.get(position);
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.chat_bubble, null);
TextView msg = (TextView) vi.findViewById(R.id.message_text);
msg.setText(message.body);
TextView dateTime = (TextView) vi.findViewById(R.id.msgDateTime);
dateTime.setText(message.dateTime);
LinearLayout layout = (LinearLayout) vi
.findViewById(R.id.bubble_layout);
LinearLayout parent_layout = (LinearLayout) vi
.findViewById(R.id.bubble_layout_parent);
// if message is mine then align to right
if (message.isMine) {
layout.setBackgroundResource(R.drawable.bubble2);
parent_layout.setGravity(Gravity.RIGHT);
}
// If not mine then align to left
else {
layout.setBackgroundResource(R.drawable.bubble1);
parent_layout.setGravity(Gravity.LEFT);
}
msg.setTextColor(Color.BLACK);
return vi;
}
public void add(ChatMessage object) {
chatMessageList.add(object);
}
}
公共类ChatMessageAdapter扩展了BaseAdapter{
专用静态充气机=空;
ArrayList聊天信息列表;
公共ChatMessageAdapter(活动,ArrayList列表){
chatMessageList=list;
充气器=(充气器)活动
.getSystemService(上下文布局\充气机\服务);
}
@凌驾
public int getCount(){
返回chatMessageList.size();
}
@凌驾
公共对象getItem(int位置){
返回位置;
}
@凌驾
公共长getItemId(int位置){
返回位置;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
ChatMessage=chatMessageList.get(位置);
视图vi=转换视图;
if(convertView==null)
vi=充气机。充气(R.layout.chat_bubble,空);
TextView msg=(TextView)vi.findviewbyd(R.id.message\u text);
msg.setText(message.body);
TextView日期时间=(TextView)vi.findViewById(R.id.msgDateTime);
dateTime.setText(message.dateTime);
线性布局布局=(线性布局)vi
.findViewById(R.id.bubble_布局);
线性布局父项_布局=(线性布局)vi
.findViewById(R.id.bubble\u布局\u父级);
//如果消息是我的,则向右对齐
如果(message.isMine){
布局。立根资源(R.drawable.bubble2);
父布局。设置重力(重力。右);
}
//如果不是我的,则向左对齐
否则{
布局。立根资源(R.drawable.bubble1);
父布局。设置重力(重力。左);
}
msg.setTextColor(颜色为黑色);
返回vi;
}
公共void添加(ChatMessage对象){
添加(对象);
}
}
我也有同样的问题!
如果使用的是导航抽屉,请在app_bar_main.xml中更改NestedScrollView的坐标布局
然后在scrollView集合中的片段中,android:nestedScrollingEnabled=“true”我遇到了同样的问题!
如果使用的是导航抽屉,请在app_bar_main.xml中更改NestedScrollView的坐标布局
然后在scrollView集合的片段中android:nestedScrollingEnabled=“true”