當前位置:首頁 » 安卓系統 » 安卓開發如何監聽輸入框布局上移

安卓開發如何監聽輸入框布局上移

發布時間: 2022-06-30 05:26:11

❶ 如何利用input事件來監聽移動端的輸入

如何利用input事件來監聽移動端的輸入
onchange事件就行了。(安卓此時需要點擊確定按鈕才會觸發,iOS則每改變一個日期,不需要點擊確定都會觸發。) 可以設置范圍,具體參考該鏈接 HTML DOM Input Date Object 中的 Input Date Object Properties 部分對 max 和 min 屬性的描述。
那個是輸入法的問題吧~搜狗遇到那種輸入框應該會自動帶了一個搜索鍵,不是用JS寫的,當然你要寫也可以,去查一下那個搜索鍵的ASCII碼,然後用onkeydown事件去觸發就行了~(不知道不同輸入法的搜索鍵的ASCII碼是否一樣~)

❷ android開發:軟鍵盤顯示的時候把布局往上頂

可以在清單文件AndroidManifest.xml中設定activty的windowInputMode屬性為adjustPan即可

android:windowSoftInputMode屬性影響活動的主窗口如何與包含屏幕上的軟鍵盤窗口交互。這個屬性的設置將會影響兩件事情:

1>軟鍵盤的狀態——是否它是隱藏或顯示——當活動(Activity)成為用戶關注的焦點。

2>活動的主窗口調整——是否減少活動主窗口大小以便騰出空間放軟鍵盤或是否當活動窗口的部分被軟鍵盤覆蓋時它的內容的當前焦點是可見的。


可以設定的值如下所示


可以使用|與符號結合多個值使用

❸ android開發中,如何讓布局整體向上平移一段距離

先把當前的整個布局嵌套在一個layout上,然後在代碼里控制之前布局的lp, 代碼如下
LayoutParams lp1 = (LayoutParams) layout.getLayoutParams();
lp1.topMargin = -30;
layout.requestLayout();
這是一種思路,希望能幫得上忙

❹ html5頁面當點擊input輸入框彈出安卓手機上鍵盤就會把背景頂了上來,頁面布局就亂了,求幫助

解決方法

1、scrollIntoView(alignWithTop):滾動瀏覽器窗口或容器元素,以便在當前視窗的可見范圍看見當前元素。

2、alignWithTop若為true,或者什麼都不傳,那麼窗口滾動之後會讓調用元素的頂部與視口頂部盡可能平齊。

3、alignWithTop若為false,調用元素會盡可能全部出現在視口中,可能的話,調用元素的底部會與視口頂部平齊,不過頂部不一定平齊。

4、該方法是唯一一個所有瀏覽器都支持的方法,類似還有如下方法,但是只有在Chrome和Safari有效。

5、代碼如下:

8、當軟鍵盤被喚起是,使用scrollTop()方法使input元素滾動到指定的位置,但是滾動的具體數值需要調試才能給出,所以這里就不再演示了。

❺ android fragment怎麼監聽上下滑動

在Android應用中,經常需要手勢滑動操作,比如上下滑動,或左右方向滑動,處理手勢滑動 。通常有兩種方法:一種是單獨實現setOnTouchListener監聽器來,另一種是構建手勢探測器

第一種方法,就是在要實現滑動的View中,實現OnTouchListener監聽事件,然後判斷KeyDonw和KeyUp 直接的位置距離來判斷滑動方向,核心實現代碼如下:

/**
* 設置上下滑動作監聽器
* @author jczmdeveloper
*/
private void setGestureListener(){
myView.setOnTouchListener(new OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch (event.getAction()) {

case MotionEvent.ACTION_DOWN:
mPosX = event.getX();
mPosY = event.getY();
break;
case MotionEvent.ACTION_MOVE:
mCurPosX = event.getX();
mCurPosY = event.getY();

break;
case MotionEvent.ACTION_UP:
if (mCurPosY - mPosY > 0
&& (Math.abs(mCurPosY - mPosY) > 25)) {
//向下滑動

} else if (mCurPosY - mPosY < 0
&& (Math.abs(mCurPosY - mPosY) > 25)) {
//向上滑動
collapse();
}

break;
}
return true;
}

});
}

第二種方法:就是構建手勢探測器,如GestureDetector mygesture = new GestureDetector(this);,然後在onFling方法中根據MotionEvent的兩個參數的 按下和滑動以及放開的位置和距離來判斷滑動方向以及滑動速度等的。要構建GestureDetector,必須要和OnTouchListener一起使用,因為必須設置Touch監聽,核心實現實例如下:

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

public class TagScrollView extends FrameLayout implements OnTouchListener, OnGestureListener{
private float mPosX, mPosY, mCurPosX, mCurPosY;
private static final int FLING_MIN_DISTANCE = 20;// 移動最小距離
private static final int FLING_MIN_VELOCITY = 200;// 移動最大速度
//構建手勢探測器
GestureDetector mygesture = new GestureDetector(this);

public TagScrollView(Context context) {
this(context, null);
}

public TagScrollView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public TagScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);

//setGestureListener();
//設置Touch監聽
this.setOnTouchListener(this);
//允許長按
this.setLongClickable(true);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
return mygesture.onTouchEvent(event);
}

@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}

@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub

}

@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
// TODO Auto-generated method stub
return false;
}

@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub

}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
// e1:第1個ACTION_DOWN MotionEvent
// e2:最後一個ACTION_MOVE MotionEvent
// velocityX:X軸上的移動速度(像素/秒)
// velocityY:Y軸上的移動速度(像素/秒)

// X軸的坐標位移大於FLING_MIN_DISTANCE,且移動速度大於FLING_MIN_VELOCITY個像素/秒
//向
if (e1.getY() - e2.getY() > FLING_MIN_DISTANCE){
// && Math.abs(velocityX) > FLING_MIN_VELOCITY) {
collapse();
}
//向上
if (e2.getY() - e1.getY() > FLING_MIN_DISTANCE
&& Math.abs(velocityX) > FLING_MIN_VELOCITY) {

}
return false;
}

}


❻ 如何實時監聽 input 和 textarea輸入框值的變化

使用這三個事件監聽輸入框值變化,不能監聽到右鍵的復制、粘貼、剪切的操作。 onkeydown 按下鍵盤上的任意鍵(不包括PrScrn鍵)時觸發;如果一直按著鍵不放,則會一直觸發此事件。 onkeypress 按下鍵盤上的可顯示字元鍵

❼ 安卓界面虛擬鍵盤彈出下面布局怎麼頂上去

有時候我們需要這種效果,鍵盤彈出,底部的內容跟隨上移。今天我就實現了這樣一個小小的效果
我們直接來看布局文件main.xml
[java] view plain
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="bottom">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="1.0">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:orientation="vertical"
android:scrollbars="vertical">
<EditText
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>

</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<Button android:id="@+id/smit_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="上 傳"
android:layout_weight="1.0"/>

<Button android:id="@+id/cancel_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="取 消" />"

</LinearLayout>
</LinearLayout>

當ScrollView里的元素想填滿ScrollView時,使用"fill_parent"是不管用的,必需為ScrollView設置:android:fillViewport="true"。

這樣做 底部的上傳和取消會隨著軟鍵盤的彈出而上移。

❽ android 點擊輸入框後,彈出鍵盤,怎麼讓輸入框往上移動(不是全屏的)

你問這個,是不是因為軟鍵盤遮擋了輸入框?如果是的話,在manifest中,對應的activity下添加屬性:android:windowSoftInputMode="adjustPan",如:

<activityandroid:name=".Activities.InputsActivity"
...
android:windowSoftInputMode="adjustPan"
/>

也可以是android:windowSoftInputMode="adjustResize",看你的需求了,你可以網上搜搜關於這個屬性的詳細解釋,有很多資料的。

❾ 安卓開發怎麼把輸入框拉到指定位置

你的按鈕沒有在gridlayout里的話,你改列數前面的列高度也為0,給imageview一個容器, 100%的高寬,verticalAlign="middle" 垂直方向居中對齊

❿ ionic框架在Android手機上點擊輸入框tabs移動到了鍵盤上面 該如何解決

用ionic 的指令布局 加個hide-on-keyboard-open指令試試

熱點內容
scratch少兒編程課程 發布:2025-04-16 17:11:44 瀏覽:642
榮耀x10從哪裡設置密碼 發布:2025-04-16 17:11:43 瀏覽:368
java從入門到精通視頻 發布:2025-04-16 17:11:43 瀏覽:89
php微信介面教程 發布:2025-04-16 17:07:30 瀏覽:312
android實現陰影 發布:2025-04-16 16:50:08 瀏覽:794
粉筆直播課緩存 發布:2025-04-16 16:31:21 瀏覽:348
機頂盒都有什麼配置 發布:2025-04-16 16:24:37 瀏覽:213
編寫手游反編譯都需要學習什麼 發布:2025-04-16 16:19:36 瀏覽:818
proteus編譯文件位置 發布:2025-04-16 16:18:44 瀏覽:369
土壓縮的本質 發布:2025-04-16 16:13:21 瀏覽:596