Android 安卓:软键盘推动整个布局,需要调整listview的大小
我有一个全屏聊天版面,上面有一个标题,上面有一个徽标,然后是一个包含所有聊天信息的列表视图,底部有编辑文本和按钮来发送聊天信息。现在,当我在编辑文本中单击时,整个布局会被推上。我需要的是,标题与标志,以始终保持在原来的位置和列表视图得到调整大小Android 安卓:软键盘推动整个布局,需要调整listview的大小,android,android-layout,android-listview,Android,Android Layout,Android Listview,我有一个全屏聊天版面,上面有一个标题,上面有一个徽标,然后是一个包含所有聊天信息的列表视图,底部有编辑文本和按钮来发送聊天信息。现在,当我在编辑文本中单击时,整个布局会被推上。我需要的是,标题与标志,以始终保持在原来的位置和列表视图得到调整大小 <LinearLayout android:layout_width="match_parent" android:layout_height="70dp" android:background="@drawable/ss
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@drawable/ss99_yellow_area_navigation_bar"
android:baselineAligned="false"
android:orientation="horizontal" >
<ImageView
android:id="@+id/back"
android:layout_width="45dp"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:adjustViewBounds="true"
android:clickable="true"
android:src="@drawable/ss99_button_back" />
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/ss99_logo_small" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="-2dp"
android:background="@drawable/ss9_yellow_bar_chat_new" >
<TextView
android:id="@+id/userOpponent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/userUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/userOpponent"
android:layout_alignBottom="@+id/userOpponent"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<ListView
android:id="@+id/chatList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:listSelector="#00000000"
android:layout_weight="1"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll">
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/ss9_yellow_area_for_bottom_and_chat_string" >
<ImageView
android:id="@+id/field1"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/ss1_field_big" />
<EditText
android:id="@+id/chatEdit"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/field1"
android:layout_alignLeft="@+id/field1"
android:layout_alignTop="@+id/field1"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="1dp"
android:background="@null"
android:inputType="textAutoCorrect|textAutoComplete"
android:textAppearance="?android:attr/textAppearanceMedium" >
</EditText>
<ImageView
android:id="@+id/chatOk"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:adjustViewBounds="false"
android:baselineAlignBottom="false"
android:clickable="true"
android:cropToPadding="false"
android:scaleType="fitEnd"
android:src="@drawable/ss4_button_go_small" />
</RelativeLayout>
</LinearLayout>
这并不能解决问题:
android:windowSoftInputMode="adjustResize"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@drawable/ss99_yellow_area_navigation_bar"
android:baselineAligned="false"
android:orientation="horizontal" >
<ImageView
android:id="@+id/back"
android:layout_width="45dp"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:adjustViewBounds="true"
android:clickable="true"
android:src="@drawable/ss99_button_back" />
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/ss99_logo_small" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="-2dp"
android:background="@drawable/ss9_yellow_bar_chat_new" >
<TextView
android:id="@+id/userOpponent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/userUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/userOpponent"
android:layout_alignBottom="@+id/userOpponent"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<ListView
android:id="@+id/chatList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:listSelector="#00000000"
android:layout_weight="1"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll">
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/ss9_yellow_area_for_bottom_and_chat_string" >
<ImageView
android:id="@+id/field1"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/ss1_field_big" />
<EditText
android:id="@+id/chatEdit"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/field1"
android:layout_alignLeft="@+id/field1"
android:layout_alignTop="@+id/field1"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="1dp"
android:background="@null"
android:inputType="textAutoCorrect|textAutoComplete"
android:textAppearance="?android:attr/textAppearanceMedium" >
</EditText>
<ImageView
android:id="@+id/chatOk"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:adjustViewBounds="false"
android:baselineAlignBottom="false"
android:clickable="true"
android:cropToPadding="false"
android:scaleType="fitEnd"
android:src="@drawable/ss4_button_go_small" />
</RelativeLayout>
</LinearLayout>
这两者都不是:
android:windowSoftInputMode="adjustPan"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@drawable/ss99_yellow_area_navigation_bar"
android:baselineAligned="false"
android:orientation="horizontal" >
<ImageView
android:id="@+id/back"
android:layout_width="45dp"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:adjustViewBounds="true"
android:clickable="true"
android:src="@drawable/ss99_button_back" />
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/ss99_logo_small" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="-2dp"
android:background="@drawable/ss9_yellow_bar_chat_new" >
<TextView
android:id="@+id/userOpponent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/userUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/userOpponent"
android:layout_alignBottom="@+id/userOpponent"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<ListView
android:id="@+id/chatList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:listSelector="#00000000"
android:layout_weight="1"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll">
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/ss9_yellow_area_for_bottom_and_chat_string" >
<ImageView
android:id="@+id/field1"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/ss1_field_big" />
<EditText
android:id="@+id/chatEdit"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/field1"
android:layout_alignLeft="@+id/field1"
android:layout_alignTop="@+id/field1"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="1dp"
android:background="@null"
android:inputType="textAutoCorrect|textAutoComplete"
android:textAppearance="?android:attr/textAppearanceMedium" >
</EditText>
<ImageView
android:id="@+id/chatOk"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:adjustViewBounds="false"
android:baselineAlignBottom="false"
android:clickable="true"
android:cropToPadding="false"
android:scaleType="fitEnd"
android:src="@drawable/ss4_button_go_small" />
</RelativeLayout>
</LinearLayout>
也许是因为我有一个全屏布局
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@drawable/ss99_yellow_area_navigation_bar"
android:baselineAligned="false"
android:orientation="horizontal" >
<ImageView
android:id="@+id/back"
android:layout_width="45dp"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:adjustViewBounds="true"
android:clickable="true"
android:src="@drawable/ss99_button_back" />
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/ss99_logo_small" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="-2dp"
android:background="@drawable/ss9_yellow_bar_chat_new" >
<TextView
android:id="@+id/userOpponent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/userUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/userOpponent"
android:layout_alignBottom="@+id/userOpponent"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<ListView
android:id="@+id/chatList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:listSelector="#00000000"
android:layout_weight="1"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll">
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/ss9_yellow_area_for_bottom_and_chat_string" >
<ImageView
android:id="@+id/field1"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/ss1_field_big" />
<EditText
android:id="@+id/chatEdit"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/field1"
android:layout_alignLeft="@+id/field1"
android:layout_alignTop="@+id/field1"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="1dp"
android:background="@null"
android:inputType="textAutoCorrect|textAutoComplete"
android:textAppearance="?android:attr/textAppearanceMedium" >
</EditText>
<ImageView
android:id="@+id/chatOk"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:adjustViewBounds="false"
android:baselineAlignBottom="false"
android:clickable="true"
android:cropToPadding="false"
android:scaleType="fitEnd"
android:src="@drawable/ss4_button_go_small" />
</RelativeLayout>
</LinearLayout>
我需要找到一种不同的方法来调整我的listView,一旦键盘出现,有什么想法吗?提前谢谢
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@drawable/ss99_yellow_area_navigation_bar"
android:baselineAligned="false"
android:orientation="horizontal" >
<ImageView
android:id="@+id/back"
android:layout_width="45dp"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:adjustViewBounds="true"
android:clickable="true"
android:src="@drawable/ss99_button_back" />
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/ss99_logo_small" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="-2dp"
android:background="@drawable/ss9_yellow_bar_chat_new" >
<TextView
android:id="@+id/userOpponent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/userUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/userOpponent"
android:layout_alignBottom="@+id/userOpponent"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<ListView
android:id="@+id/chatList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:listSelector="#00000000"
android:layout_weight="1"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll">
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/ss9_yellow_area_for_bottom_and_chat_string" >
<ImageView
android:id="@+id/field1"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/ss1_field_big" />
<EditText
android:id="@+id/chatEdit"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/field1"
android:layout_alignLeft="@+id/field1"
android:layout_alignTop="@+id/field1"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="1dp"
android:background="@null"
android:inputType="textAutoCorrect|textAutoComplete"
android:textAppearance="?android:attr/textAppearanceMedium" >
</EditText>
<ImageView
android:id="@+id/chatOk"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:adjustViewBounds="false"
android:baselineAlignBottom="false"
android:clickable="true"
android:cropToPadding="false"
android:scaleType="fitEnd"
android:src="@drawable/ss4_button_go_small" />
</RelativeLayout>
</LinearLayout>
这是我的布局
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@drawable/ss99_yellow_area_navigation_bar"
android:baselineAligned="false"
android:orientation="horizontal" >
<ImageView
android:id="@+id/back"
android:layout_width="45dp"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:adjustViewBounds="true"
android:clickable="true"
android:src="@drawable/ss99_button_back" />
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/ss99_logo_small" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="-2dp"
android:background="@drawable/ss9_yellow_bar_chat_new" >
<TextView
android:id="@+id/userOpponent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/userUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/userOpponent"
android:layout_alignBottom="@+id/userOpponent"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<ListView
android:id="@+id/chatList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:listSelector="#00000000"
android:layout_weight="1"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll">
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/ss9_yellow_area_for_bottom_and_chat_string" >
<ImageView
android:id="@+id/field1"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/ss1_field_big" />
<EditText
android:id="@+id/chatEdit"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/field1"
android:layout_alignLeft="@+id/field1"
android:layout_alignTop="@+id/field1"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="1dp"
android:background="@null"
android:inputType="textAutoCorrect|textAutoComplete"
android:textAppearance="?android:attr/textAppearanceMedium" >
</EditText>
<ImageView
android:id="@+id/chatOk"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:adjustViewBounds="false"
android:baselineAlignBottom="false"
android:clickable="true"
android:cropToPadding="false"
android:scaleType="fitEnd"
android:src="@drawable/ss4_button_go_small" />
</RelativeLayout>
</LinearLayout>
在
滚动视图中添加布局
并在清单文件中添加android:windowSoftInputMode=“adjustResize”
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@drawable/ss99_yellow_area_navigation_bar"
android:baselineAligned="false"
android:orientation="horizontal" >
<ImageView
android:id="@+id/back"
android:layout_width="45dp"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:adjustViewBounds="true"
android:clickable="true"
android:src="@drawable/ss99_button_back" />
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/ss99_logo_small" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="-2dp"
android:background="@drawable/ss9_yellow_bar_chat_new" >
<TextView
android:id="@+id/userOpponent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/userUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/userOpponent"
android:layout_alignBottom="@+id/userOpponent"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<ListView
android:id="@+id/chatList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:listSelector="#00000000"
android:layout_weight="1"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll">
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/ss9_yellow_area_for_bottom_and_chat_string" >
<ImageView
android:id="@+id/field1"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/ss1_field_big" />
<EditText
android:id="@+id/chatEdit"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/field1"
android:layout_alignLeft="@+id/field1"
android:layout_alignTop="@+id/field1"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="1dp"
android:background="@null"
android:inputType="textAutoCorrect|textAutoComplete"
android:textAppearance="?android:attr/textAppearanceMedium" >
</EditText>
<ImageView
android:id="@+id/chatOk"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:adjustViewBounds="false"
android:baselineAlignBottom="false"
android:clickable="true"
android:cropToPadding="false"
android:scaleType="fitEnd"
android:src="@drawable/ss4_button_go_small" />
</RelativeLayout>
</LinearLayout>
在ListView
上设置OnTouchListener()
,以便滚动视图中的子视图执行触摸操作
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@drawable/ss99_yellow_area_navigation_bar"
android:baselineAligned="false"
android:orientation="horizontal" >
<ImageView
android:id="@+id/back"
android:layout_width="45dp"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:adjustViewBounds="true"
android:clickable="true"
android:src="@drawable/ss99_button_back" />
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/ss99_logo_small" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="-2dp"
android:background="@drawable/ss9_yellow_bar_chat_new" >
<TextView
android:id="@+id/userOpponent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/userUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/userOpponent"
android:layout_alignBottom="@+id/userOpponent"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<ListView
android:id="@+id/chatList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:listSelector="#00000000"
android:layout_weight="1"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll">
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/ss9_yellow_area_for_bottom_and_chat_string" >
<ImageView
android:id="@+id/field1"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/ss1_field_big" />
<EditText
android:id="@+id/chatEdit"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/field1"
android:layout_alignLeft="@+id/field1"
android:layout_alignTop="@+id/field1"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="1dp"
android:background="@null"
android:inputType="textAutoCorrect|textAutoComplete"
android:textAppearance="?android:attr/textAppearanceMedium" >
</EditText>
<ImageView
android:id="@+id/chatOk"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:adjustViewBounds="false"
android:baselineAlignBottom="false"
android:clickable="true"
android:cropToPadding="false"
android:scaleType="fitEnd"
android:src="@drawable/ss4_button_go_small" />
</RelativeLayout>
</LinearLayout>
ListView lv = (ListView) findViewById(R.id.layout_lv);
lv.setOnTouchListener(new OnTouchListener() {
// Setting on Touch Listener for handling the touch inside ScrollView
@Override
public boolean onTouch(View v, MotionEvent event) {
// Disallow the touch request for parent scroll on touch of child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
尝试将其添加到Manifest.xml中的活动中
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@drawable/ss99_yellow_area_navigation_bar"
android:baselineAligned="false"
android:orientation="horizontal" >
<ImageView
android:id="@+id/back"
android:layout_width="45dp"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:adjustViewBounds="true"
android:clickable="true"
android:src="@drawable/ss99_button_back" />
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/ss99_logo_small" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="-2dp"
android:background="@drawable/ss9_yellow_bar_chat_new" >
<TextView
android:id="@+id/userOpponent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/userUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/userOpponent"
android:layout_alignBottom="@+id/userOpponent"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<ListView
android:id="@+id/chatList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:listSelector="#00000000"
android:layout_weight="1"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll">
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/ss9_yellow_area_for_bottom_and_chat_string" >
<ImageView
android:id="@+id/field1"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/ss1_field_big" />
<EditText
android:id="@+id/chatEdit"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/field1"
android:layout_alignLeft="@+id/field1"
android:layout_alignTop="@+id/field1"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="1dp"
android:background="@null"
android:inputType="textAutoCorrect|textAutoComplete"
android:textAppearance="?android:attr/textAppearanceMedium" >
</EditText>
<ImageView
android:id="@+id/chatOk"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:adjustViewBounds="false"
android:baselineAlignBottom="false"
android:clickable="true"
android:cropToPadding="false"
android:scaleType="fitEnd"
android:src="@drawable/ss4_button_go_small" />
</RelativeLayout>
</LinearLayout>
<activity
android:windowSoftInputMode="stateVisible|adjustNothing">
</activity>
好的,实际上我自己解决了这个问题,但我认为这只不过是一个黑客行为,所以我可能会在以后再次讨论这个问题。但关键是它有效(在星系S4上进行了测试)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@drawable/ss99_yellow_area_navigation_bar"
android:baselineAligned="false"
android:orientation="horizontal" >
<ImageView
android:id="@+id/back"
android:layout_width="45dp"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:adjustViewBounds="true"
android:clickable="true"
android:src="@drawable/ss99_button_back" />
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/ss99_logo_small" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="-2dp"
android:background="@drawable/ss9_yellow_bar_chat_new" >
<TextView
android:id="@+id/userOpponent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/userUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/userOpponent"
android:layout_alignBottom="@+id/userOpponent"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<ListView
android:id="@+id/chatList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:listSelector="#00000000"
android:layout_weight="1"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll">
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/ss9_yellow_area_for_bottom_and_chat_string" >
<ImageView
android:id="@+id/field1"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/ss1_field_big" />
<EditText
android:id="@+id/chatEdit"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/field1"
android:layout_alignLeft="@+id/field1"
android:layout_alignTop="@+id/field1"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="1dp"
android:background="@null"
android:inputType="textAutoCorrect|textAutoComplete"
android:textAppearance="?android:attr/textAppearanceMedium" >
</EditText>
<ImageView
android:id="@+id/chatOk"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:adjustViewBounds="false"
android:baselineAlignBottom="false"
android:clickable="true"
android:cropToPadding="false"
android:scaleType="fitEnd"
android:src="@drawable/ss4_button_go_small" />
</RelativeLayout>
</LinearLayout>
我根据显示的软键盘的高度调整listView的大小,并在键盘离开后重新调整它的大小
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@drawable/ss99_yellow_area_navigation_bar"
android:baselineAligned="false"
android:orientation="horizontal" >
<ImageView
android:id="@+id/back"
android:layout_width="45dp"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:adjustViewBounds="true"
android:clickable="true"
android:src="@drawable/ss99_button_back" />
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/ss99_logo_small" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="-2dp"
android:background="@drawable/ss9_yellow_bar_chat_new" >
<TextView
android:id="@+id/userOpponent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/userUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/userOpponent"
android:layout_alignBottom="@+id/userOpponent"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<ListView
android:id="@+id/chatList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:listSelector="#00000000"
android:layout_weight="1"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll">
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/ss9_yellow_area_for_bottom_and_chat_string" >
<ImageView
android:id="@+id/field1"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/ss1_field_big" />
<EditText
android:id="@+id/chatEdit"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/field1"
android:layout_alignLeft="@+id/field1"
android:layout_alignTop="@+id/field1"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="1dp"
android:background="@null"
android:inputType="textAutoCorrect|textAutoComplete"
android:textAppearance="?android:attr/textAppearanceMedium" >
</EditText>
<ImageView
android:id="@+id/chatOk"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:adjustViewBounds="false"
android:baselineAlignBottom="false"
android:clickable="true"
android:cropToPadding="false"
android:scaleType="fitEnd"
android:src="@drawable/ss4_button_go_small" />
</RelativeLayout>
</LinearLayout>
private static boolean keyboardHidden = true;
private static int reduceHeight = 0;
//...
//...
final View decorView = this.getWindow().getDecorView();
decorView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect rect = new Rect();
decorView.getWindowVisibleDisplayFrame(rect);
int displayHeight = rect.bottom - rect.top;
int height = decorView.getHeight();
boolean keyboardHiddenTemp = (double)displayHeight / height > 0.8 ;
int mylistviewHeight = mylistview.getMeasuredHeight();
if (keyboardHiddenTemp != keyboardHidden) {
keyboardHidden = keyboardHiddenTemp;
if (!keyboardHidden) {
reduceHeight = height - displayHeight;
LinearLayout.LayoutParams mParam = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,mylistviewHeight - reduceHeight);
mylistview.setLayoutParams(mParam);
mylistview.requestLayout();
} else {
LinearLayout.LayoutParams mParam = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,mylistviewHeight + reduceHeight);
mylistview.setLayoutParams(mParam);
mylistview.requestLayout();
}
}
}
});
将此添加到您的活动中
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@drawable/ss99_yellow_area_navigation_bar"
android:baselineAligned="false"
android:orientation="horizontal" >
<ImageView
android:id="@+id/back"
android:layout_width="45dp"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:adjustViewBounds="true"
android:clickable="true"
android:src="@drawable/ss99_button_back" />
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/ss99_logo_small" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="-2dp"
android:background="@drawable/ss9_yellow_bar_chat_new" >
<TextView
android:id="@+id/userOpponent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/userUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/userOpponent"
android:layout_alignBottom="@+id/userOpponent"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<ListView
android:id="@+id/chatList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:listSelector="#00000000"
android:layout_weight="1"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll">
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/ss9_yellow_area_for_bottom_and_chat_string" >
<ImageView
android:id="@+id/field1"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/ss1_field_big" />
<EditText
android:id="@+id/chatEdit"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/field1"
android:layout_alignLeft="@+id/field1"
android:layout_alignTop="@+id/field1"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="1dp"
android:background="@null"
android:inputType="textAutoCorrect|textAutoComplete"
android:textAppearance="?android:attr/textAppearanceMedium" >
</EditText>
<ImageView
android:id="@+id/chatOk"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:adjustViewBounds="false"
android:baselineAlignBottom="false"
android:clickable="true"
android:cropToPadding="false"
android:scaleType="fitEnd"
android:src="@drawable/ss4_button_go_small" />
</RelativeLayout>
</LinearLayout>
<activity
android:windowSoftInputMode="adjustResize"
</activity>
在ScrollView中添加布局已经想到了这一点,但是我的布局有一个listview,listvies和ScrollView不能很好地结合在一起。没有理想的效果,布局保持在原来的位置,但是现在键盘总是可见的,并且与编辑文本重叠。你看不到你所键入的内容是否可以通过在清单文件中使用adjustNothing
来获得键盘高度?这种方法还解决了一些其他问题,我的列表视图在scrollview中折叠。我不确定我是否想走这条路它飞得离屏幕很远