[英]Unable to hide FrameLayout
我正在開發Android即時聊天應用程序。在聊天活動中,我正在使用FrameLayout。以下是xml文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FCAB26"
android:orientation="vertical"
android:weightSum="1">
<ListView
android:id="@+id/list_view_messages"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight=".60"
android:background="@null"
android:divider="@null"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"></ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight=".10"
android:orientation="horizontal"
android:weightSum="1">
<ImageView
android:id="@+id/imgSmile"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".10"
android:src="@drawable/ic_msg_panel_smiles"
android:layout_gravity="center_vertical"
android:layout_marginRight="-10sp"/>
<com.rockerhieu.emojicon.EmojiconEditText
android:id="@+id/edtMessage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:hint="Enter Message"
android:layout_weight=".60"></com.rockerhieu.emojicon.EmojiconEditText>
<Button
android:id="@+id/btnSendMessage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight=".30"
android:gravity="center"
android:onClick="onClick"
android:text="Send Message" />
</LinearLayout>
<FrameLayout
android:id="@+id/emojicons"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".30"
android:visibility="gone" />
我已經將框架的可見性設置為已經消失但仍然占據了該區域。我希望FrameLayout不要在開始時占用空間.ImageView,EditText和Send Message按鈕應位於屏幕的底部。單擊ImageView,顯示表情符號面板,隱藏了軟鍵盤,我使用了以下代碼:
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
hideKeyboard(); // hiding the keyboard
showEmojiPopUp(!showEmoji);
}
});
// Displaying the FrameLayout containing the list of Emoticons
public void showEmojiPopUp(boolean showEmoji) {
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.emojicons);
frameLayout.setVisibility(View.VISIBLE);
}
// Hiding the FrameLayout containing the list of Emoticons
public void hideEmojiPopUp(boolean hideEmoji) {
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.emojicons);
frameLayout.setVisibility(View.INVISIBLE);
}
它工作正常。所以我的問題是如何在創建活動時將我的框架設置為不可見。它應該在clickinh圖像視圖上顯示。軟鍵盤和FameLayout的高度應該相同。屏幕截圖如下:
1.Screenshot
2.單擊圖像視圖
請幫我解決這個問題。
發生這種情況是因為您正在使用權重。 刪除weightsum和layouts_weight並使用wrap_content。
<FrameLayout
android:id="@+id/emojicons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
並動態地給framelayout它的高度。
int deviceHeight;
FrameLayout frameLayout;
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
deviceHeight = size.y;
frameLayout= (FrameLayout ) findViewById(R.id.emojicons);
frameLayout.getLayoutParams().height = (int) (deviceHeight / 3);
frameLayout.requestLayout();
而不是
public void hideEmojiPopUp(boolean hideEmoji) {
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.emojicons);
frameLayout.setVisibility(View.INVISIBLE);
}
用這個
public void hideEmojiPopUp(boolean hideEmoji) {
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.emojicons);
frameLayout.setVisibility(View.GONE);
}
使用View.GONE
而不是View.INVISIBLE
// Hiding the FrameLayout containing the list of Emoticons
public void hideEmojiPopUp(boolean hideEmoji) {
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.emojicons);
frameLayout.setVisibility(View.GONE);
}
View.INVISIBLE
此視圖不可見,但它仍占用布局空間。
View.GONE
此視圖不可見,並且不需要任何空間用於布局。
您使用的是INVISIBLE而不是GONE。 INVISIBLE只隱藏視圖但不留空間。如果消失,它也會刪除空白區域。 所以在這里使用GONE。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.