• Stars
    star
    126
  • Rank 283,141 (Top 6 %)
  • Language
    Java
  • Created over 8 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Android仿手机QQ空间动态评论,自动定位到输入框

《Android仿手机QQ空间动态评论,自动定位到输入框》

手机QQ空间浏览好友动态时,可以直接对动态评论,点击某条评论,动态列表自动滚动,使输入框刚好在该评论下面,而不会覆盖住评论内容。如下图所示,

img

首先要实现输入框刚好在输入面板上面,且动态列表不会被挤上去。可以使用对话框的形式,这样输入框不会影响原有的布局,弹出的对话框布局如下所示,点击EditText时,红色块的内容将位于输入法上面。在这里我把ScrollerView的背景设为透明。其实QQ空间的输入框也是以对话框的形式弹出,因为弹出对话框时,原本全屏的布局突然多了一条状态栏。

接着就是要让点击的评论刚好在评论输入框上面,可以使用ListView.smoothScrollBy(distance, duration)让列表滚动到相应位置,但是难点是如何计算出滚动的距离distance。 如下图所示,我们主要计算弹出输入面板后的输入框和评论之间的距离(绿色线条的长度)。通过View.getLocationOnScreen()方法可以计算出view在屏幕上的坐标(x,y),那么列表滑动的距离distance = listview的y坐标 - 输入框的y坐标。

img

CommonFun

最后要弄的就是评论中,评论者、接收者和评论内容用不同的颜色显示,且点击时有点击效果。这里可以通过下面的代码实现,

TextView.setText(Html.fromHtml(content, imageGettor, tagHandler))

自定义标签,通过自定义的标签解析类Html.TagHandler来响应不同标签的操作。这里我自定义了commentator、receiver、content标签,列入一条评论的字符串形式为“用户1 回复 用户2:评论内容”,点击content标签时对该评论的评论者进行回复。 CustomTagHandler

在ListView中,因为Item里面的子View使用了ClickableSpan,导致ListView的OnItemClickListener失效,解决的方法可以在getView中加入下列代码,阻止ListView里面的子View拦截焦点。

public View getView(int position, View convertView, ViewGroup parent) {  
    if (convertView != null) {  
            //防止ListView的OnItemClick与item里面子view的点击发生冲突  
    ((ViewGroup) convertView).setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);  
    }  
}

设置点击的文字背景色:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"  
          ...  
          android:textColorLink="@color/selector_comment_name"  
          android:textColorHighlight="#44000000"  
        />  
<!-- 上面两个属性(textColorLink、textColorHighlight)要同时设置,而且textColorLink必须设置为ColorList!!!!!!!!! 
-->  

难点都已经解决了,最后实现的效果如下:

img

More Repositories

1

Doodle

Image doodle for Android, with functions such as undo, zoom, move, text, image, etc. Also a powerful, customizable and extensible doodle framework & multi-function drawing board. Android图片涂鸦,具有撤消,缩放,移动,添加文字,贴图等功能。还是一个功能强大,可自定义和可扩展的涂鸦框架、多功能画板。
Java
1,111
star
2

Androids

提供了一些工具类以及自定义View,用于日常的Android快速开发。something about android
Java
477
star
3

Graffiti

android图片涂鸦,具有设置画笔,撤销,缩放移动等功能。Graffiti for android.
Java
330
star
4

TiledMapView

Tiled map loader for Android , based on the pyramid model, supports a variety of projections, including Web Mercator projection, latitude and longitude projection and custom projection; supports locating, adding layers and overlays. Android瓦片地图加载控件,基于金字塔模型,支持多种投影,包括Web墨卡托投影,经纬度直投及自定义投影等;支持定位,添加图层和覆盖物。
Java
70
star
5

OverScroll

Use CoordinatorLayout+Behavior to achieve elastic scrolling and inertial scrolling for list. 利用CoordinatorLayout+Behavior实现弹性滚动和惯性滚动效果(类似微信首页).
Java
41
star
6

tile-cutter

Cut the picture into small pieces (tiles) according to the pyramid model; support for cutting images, cutting maps, display in tiled maps for Web Mercator projection and latitude and longitude projection. 瓦片切割工具,按照金字塔模型把图片切成小片;支持图片切割,地图切割,可用于Web墨卡托投影和经纬度投影的瓦片地图中显示。
Python
41
star
7

OpenGLESIntroduction

Get to know Android OpenGL ES by displaying a picture. 从显示一张图片开始学习Android OpenGL ES
Java
21
star
8

ImageSelector

图片选择器
Java
4
star
9

InAppSkin

一种应用内换肤方案,利用安卓系统的`Style+Theme`机制进行应用内换肤。
Java
3
star
10

bat

Bat博客系统,a simple blog system
JavaScript
2
star
11

EasyAdapterForRecyclerView-kotlin

用于RecyclerView的适配器,可设置点击模式、单选和多选模式。kotlin-android项目。
Kotlin
2
star
12

QMUI_Android_extend

针对QMUI的补充和拓展
Java
2
star
13

common

common
HTML
1
star
14

SoudWaveView

模拟音频波动组件
Java
1
star