怎样让一个textview滚动条禁止弹出键盘编辑,而且能够滚动

如何解决软键盘弹出引起的各种不适 - 埋头独行的日子 - ITeye技术网站
博客分类:
在做登录和注册页面的时候,经常会遇到诸如软键盘挡住输入框的情况,android为此提供了一系列的的配置参数供选择,你可以在androidmanufist.xml的对应Activity的windowSoftInputMode属性中选择如下4者之一进行配置(紫色字):
Adjustment option for :
set to have a window not adjust for a shown input method.
Adjustment option for :
set to have a window pan when an input method is shown, so it doesn't need to deal with resizing but just panned by
the framework to ensure the current input focus is visible.
Adjustment option for :
set to allow the window to be resized when an input method is shown, so that its contents are not covered by the input method.
Adjustment option for :
nothing specified.
&activity android:name=".LoginAc"
android:label="@string/app_name"
android:windowSoftInputMode="stateHidden|adjustResize"&
&intent-filter&
&action android:name="android.intent.action.MAIN" /&
&category android:name="android.intent.category.LAUNCHER" /&
&/intent-filter&
&/activity&
四个参数意思如下:
不调整(输入法完全直接覆盖住,未开放此参数)
把整个Layout顶上去露出获得焦点的EditText,不压缩多余空间,见图1
整个Layout重新编排,重新分配多余空间,见图2
系统自己根据内容自行选择上两种方式的一种执行(默认配置)
这里的多余空间指的是控件们通过weight分配机制得到的额外空间。
代码实现方式为:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
但是,这样的配置方法一般都很难完全满足需要,有得应用会做得比较好,让顶上去的Layout能够通过scrollbar滚动。这种解决方法网上有各种介绍,本人也是第一时间从网上找解决方法参考,但最终发现都并未把原理说清,而且大多数有错误,或者有多余配置,于是,我从android系统中源码中找参考案例,在Email应用中,找到了我想要的。效果如图4,5。
其对应的Activity是AccountSetupBasics.java,对应的xml文件为account_setup_basics.xml。
来学习下它的xml写法:
&?xml version="1.0" encoding="utf-8"?&
&ScrollView xmlns:android="/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbarStyle="outsideInset" &
&LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" &
&LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" &
android:id="@+id/instructions"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:textSize="20sp"
android:text="@string/accounts_welcome"
android:textColor="?android:attr/textColorPrimary" /&
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" /&
android:id="@+id/account_email"
android:hint="@string/account_setup_basics_email_hint"
android:inputType="textEmailAddress"
android:imeOptions="actionNext"
android:layout_height="wrap_content"
android:layout_width="fill_parent" /&
android:id="@+id/account_password"
android:hint="@string/account_setup_basics_password_hint"
android:inputType="textPassword"
android:imeOptions="actionDone"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:nextFocusDown="@+id/next" /&
android:id="@+id/account_default"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/account_setup_basics_default_label"
android:visibility="gone" /&
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" /&
&/LinearLayout&
&RelativeLayout
android:layout_width="fill_parent"
android:layout_height="54dip"
android:background="@android:drawable/bottom_bar" &
android:id="@+id/manual_setup"
android:text="@string/account_setup_basics_manual_setup_action"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:minWidth="@dimen/button_minWidth"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" /&
android:id="@+id/next"
android:text="@string/next_action"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:minWidth="@dimen/button_minWidth"
android:drawableRight="@drawable/button_indicator_next"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" /&
&/RelativeLayout&
&/LinearLayout&
&/ScrollView&
它完全把ScrollView作为了一个根Layout,而不是网上好多文章写的在一个Linearlayout里面嵌入一个ScrollView(貌似这种是行不通的)。
然后把我们原来的根Layout搬入ScrollView(ScrollView只能有一个子控件),我查了下androidmanifist.xml和代码,未做任何以上2种方法的配置。
它定义了2个0dip的View帮助分配空间(设置其weight吃掉剩余空间,保证输入框处于界面中心位置),可以猜测出这里系统调用的是
如此,完美的解决我们遇到的问题。
另外,网上有人说想用
浏览: 26819 次
来自: 深圳
不过应该可以用的吧, 楼主辛苦了
楼主生活很充实。
楼主,我最近也想Android入门,看了你的文章,有很大指引。 ...
你好!你的文章没有配置.xml我不太明白
能否再详细一点lo ...
如果里面是个listview 就不好用了JS中当弹出一个DIV后,如何禁止滚动和编辑页面???_百度知道
JS中当弹出一个DIV后,如何禁止滚动和编辑页面???
提问者采纳
hidden这样就不会显示滚动条,页面上的任何元素都不可点击(页面中元素的默认z-index为0:absolute,position.z-index,width:100%;z-index,如果有高的z-index需要将div2的z-index设置的更高些)禁止滚动可以给body添加overflow:101再使用一个层div2,height:这样div2会覆盖整个页面:100%:100将弹出层设置为position
提问者评价
太感谢了,真心有用
其他类似问题
div的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁如何点击textview的时候不弹出虚拟键盘 求方法_百度知道
如何点击textview的时候不弹出虚拟键盘 求方法
我有更好的答案
按默认排序
其他类似问题
虚拟键盘的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁ListView里面有EditTextView,解决弹出键盘后EditView不能获取焦点的问题 - 推酷
ListView里面有EditTextView,解决弹出键盘后EditView不能获取焦点的问题
虽然ListView里面动态生成EditTextView不是Android UI Friendly, 但是需求就是这样,那就硬着头皮去做了
遇到的问题是点击EditText,键盘弹出后,输入光标会消失,需要再点击一次才能获取光标,这个大概是因为listview不能很好的处理EditText作为item的情况,弹出键盘后应该view是重新生成的。
折腾了一天,解决方案如下:
布局文件(nothing special):
&?xml version=&1.0& encoding=&utf-8&?&
&RelativeLayout xmlns:android=&/apk/res/android&
android:layout_width=&fill_parent&
android:layout_height=&fill_parent& &
&FrameLayout
android:id=&@+id/booking1_frameLayout&
android:layout_width=&fill_parent&
android:layout_height=&40dp&
android:background=&@drawable/header& &
style=&@style/title_text_style&
android:text=&@string/booking2& /&
&/FrameLayout&
android:id=&@+id/book2_listview&
android:layout_width=&fill_parent&
android:layout_height=&fill_parent&
android:layout_below=&@id/booking1_frameLayout&
android:divider=&@null&
android:paddingLeft=&10dp&
android:paddingRight=&10dp& /&
&/RelativeLayout&
关键代码:
在listView的adapter的getView方法里:
//点击时记录下现在点击的是哪个EditText,也就是在编辑哪一个EditText
viewHolderChild.name.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
touchedPosition =
if (touchedPosition == position) {
// 如果当前的行下标和点击事件中保存的index一致,手动为EditText设置焦点。
viewHolderChild.name.requestFocus();
viewHolderChild.name.clearFocus();
主要是对listview的机制还不很了解。
已发表评论数()
&&登&&&陆&&
已收藏到推刊!
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见iOS 问题:我想在动态添加的imageView上添加触摸事件。每一张图片放在一个uiimageView上,图片以表格的形式排成多行多列。我现在要做的是当触摸一个uiimageView的时候,可以查看图片的原图,如果图片太大的话,可以通过手指的移动滚动显示,右上角有一个关闭的按钮,点击可以关闭。请问该怎么做。如果想看完整代码的话,可以联系我,我给你发。
代码如下:
//切换到显示图片视图的方法
- (void)switchToImageView:(NSArray*)images{
//让_URLUITextField释放第一响应者,键盘关闭
[_URLUITextField resignFirstResponder];
NNGImageViewController *imageViewController = [[NMGViewController alloc] initWithNibName:@"NNGImageViewController" bundle:nil];
self._imageViewController = imageViewC
UIScrollView *scrollView
=[[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0,self.view.frame.size.width, 400)];
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;
[imageViewController.view addSubview:scrollView];
int imageCount = [images count]; //图片数组里的图片总数, 即[images count]
float width = 90.0f;
//imageView宽度
float height = 80.0f;
//imageView高度
float columnGap = (self.view.frame.size.width-width*3)/4; //列间距,即左右间隔
float rowGap = 15.0f; //行间距,即上下间隔
int row = imageCount%3==0 ? imageCount/3 : (imageCount/3>=2?imageCount/3+1:(imageCount -
=2?imageCount/3+1:(imageCount" />
我想在动态添加的imageView上添加触摸事件。每一张图片放在一个uiimageView上,图片以表格的形式排成多行多列。我现在要做的是当触摸一个uiimageView的时候,可以查看图片的原图,如果图片太大的话,可以通过手指的移动滚动显示,右上角有一个关闭的按钮,点击可以关闭。请问该怎么做。如果想看完整代码的话,可以联系我,我给你发。
代码如下:
//切换到显示图片视图的方法
- (void)switchToImageView:(NSArray*)images{
//让_URLUITextField释放第一响应者,键盘关闭
[_URLUITextField resignFirstResponder];
NNGImageViewController *imageViewController = [[NMGViewController alloc] initWithNibName:@"NNGImageViewController" bundle:nil];
self._imageViewController = imageViewC
UIScrollView *scrollView
=[[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0,self.view.frame.size.width, 400)];
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;
[imageViewController.view addSubview:scrollView];
int imageCount = [images count]; //图片数组里的图片总数, 即[images count]
float width = 90.0f;
//imageView宽度
float height = 80.0f;
//imageView高度
float columnGap = (self.view.frame.size.width-width*3)/4; //列间距,即左右间隔
float rowGap = 15.0f; //行间距,即上下间隔
int row = imageCount%3==0 ? imageCount/3 : (imageCount/3&=2?imageCount/3+1:(imageCount
共有 1 个回答
参考这份代码:
登录后方可回复
登录后方可回答
耗时 0.1370 秒

我要回帖

更多关于 textview自动滚动 的文章

 

随机推荐