大家下午好!
我在listView彈出窗口中遇到了一些問題。
單擊任何列表元素時,會彈出一個對話框並顯示遊戲的所有信息(它是遊戲的TicTacToe歷史記錄)。我已經完成了模式的佈局,預覽顯示爲我想要的。
但是,當我在Android上運行,一些元素是 「切」 as shown here ...彈出式窗口未按預期顯示(Android/Xamarin)
當前活動代碼:
private void List_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
LayoutInflater inflater = (LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);
View popup = inflater.Inflate(Resource.Layout.DesenhoJogo, null); //DesenhoJogo is my Layout for the modal
PopupWindow janela = new PopupWindow(popup, ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent, false);
janela.ShowAsDropDown(popup, Android.Views.ViewGroup.LayoutParams.WrapContent, Android.Views.ViewGroup.LayoutParams.WrapContent);
Button voltar = popup.FindViewById<Button>(Resource.Id.btnVoltar);
voltar.Click += (s, o) => { janela.Dismiss(); };
}
編輯: 佈局代碼:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:p1="http://schemas.android.com/apk/res/android"
p1:orientation="vertical"
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="match_parent"
p1:layout_height="match_parent"
p1:id="@+id/linearLayout1"
p1:background="@drawable/fundoverde"
p1:weightSum="3">
<RelativeLayout
p1:layout_width="match_parent"
p1:layout_height="wrap_content"
p1:id="@+id/relativeLayout1"
p1:layout_marginLeft="5dp"
p1:layout_marginRight="5dp">
<ImageView
p1:src="@drawable/xbranco"
p1:layout_width="35dp"
p1:layout_height="35dp"
p1:layout_margin="5dp"
p1:id="@+id/xJogadorBranco" />
<ImageView
p1:src="@drawable/obranco"
p1:layout_width="35dp"
p1:layout_height="35dp"
p1:layout_margin="5dp"
p1:id="@+id/oJogadorBranco"
p1:layout_below="@id/xJogadorBranco" />
<TextView
p1:text="Jogador 1"
p1:layout_width="match_parent"
p1:layout_height="35dp"
p1:layout_toRightOf="@id/xJogadorBranco"
p1:id="@+id/nomeJogador1"
p1:layout_margin="5dp"
p1:gravity="fill"
p1:textSize="25dp" />
<TextView
p1:text="Jogador 2"
p1:layout_width="match_parent"
p1:layout_height="35dp"
p1:layout_toRightOf="@id/oJogadorBranco"
p1:id="@+id/nomeJogador2"
p1:layout_margin="5dp"
p1:gravity="fill"
p1:textSize="25dp"
p1:layout_below="@id/nomeJogador1" />
<TextView
p1:text="Jogadas: "
p1:layout_width="match_parent"
p1:layout_height="35dp"
p1:id="@+id/jogadas"
p1:gravity="center"
p1:textSize="25dp"
p1:layout_below="@+id/nomeJogador2"
p1:layout_marginBottom="5dp"
p1:layout_marginRight="5dp"
p1:layout_marginLeft="5dp" />
<TextView
p1:text="Vencedor: "
p1:layout_width="match_parent"
p1:layout_height="35dp"
p1:id="@+id/vencedor"
p1:gravity="center"
p1:textSize="25dp"
p1:layout_below="@+id/jogadas"
p1:padding="5dp"
p1:layout_marginBottom="5dp"
p1:layout_marginLeft="5dp"
p1:layout_marginRight="5dp" />
</RelativeLayout>
<LinearLayout
p1:layout_width="match_parent"
p1:layout_height="wrap_content"
p1:orientation="vertical"
p1:weightSum="3"
p1:background="@drawable/velha"
p1:layout_weight="3"
p1:id="@+id/linearLayout5"
p1:layout_marginBottom="10dp"
p1:layout_marginLeft="5dp"
p1:layout_marginRight="5dp"
p1:layout_marginTop="5dp">
<LinearLayout
p1:layout_width="match_parent"
p1:layout_height="0dp"
p1:layout_weight="1"
p1:orientation="horizontal"
p1:weightSum="3"
p1:id="@+id/linearLayout2">
<Button xmlns:tools="http://schemas.android.com/tools"
p1:id="@+id/pos00"
p1:layout_width="0dp"
p1:layout_height="fill_parent"
p1:layout_weight="1"
tools:visibility="visible"
p1:scaleType="centerInside"
p1:background="@android:color/transparent" />
<Button xmlns:tools="http://schemas.android.com/tools"
p1:id="@+id/pos01"
p1:layout_width="0dp"
p1:layout_height="fill_parent"
p1:layout_weight="1"
tools:visibility="visible"
p1:scaleType="centerInside"
p1:background="@android:color/transparent" />
<Button xmlns:tools="http://schemas.android.com/tools"
p1:id="@+id/pos02"
p1:layout_width="0dp"
p1:layout_height="fill_parent"
p1:layout_weight="1"
tools:visibility="visible"
p1:scaleType="centerInside"
p1:background="@android:color/transparent" />
</LinearLayout>
<LinearLayout
p1:layout_width="match_parent"
p1:layout_height="0dp"
p1:layout_weight="1"
p1:orientation="horizontal"
p1:weightSum="3"
p1:id="@+id/linearLayout3">
<Button xmlns:tools="http://schemas.android.com/tools"
p1:id="@+id/pos10"
p1:layout_width="0dp"
p1:layout_height="fill_parent"
p1:layout_weight="1"
tools:visibility="visible"
p1:scaleType="centerInside"
p1:background="@android:color/transparent" />
<Button xmlns:tools="http://schemas.android.com/tools"
p1:id="@+id/pos11"
p1:layout_width="0dp"
p1:layout_height="fill_parent"
p1:layout_weight="1"
tools:visibility="visible"
p1:scaleType="centerInside"
p1:background="@android:color/transparent" />
<Button xmlns:tools="http://schemas.android.com/tools"
p1:id="@+id/pos12"
p1:layout_width="0dp"
p1:layout_height="fill_parent"
p1:layout_weight="1"
tools:visibility="visible"
p1:scaleType="centerInside"
p1:background="@android:color/transparent" />
</LinearLayout>
<LinearLayout
p1:layout_width="match_parent"
p1:layout_height="0dp"
p1:layout_weight="1"
p1:orientation="horizontal"
p1:weightSum="3"
p1:id="@+id/linearLayout4">
<Button xmlns:tools="http://schemas.android.com/tools"
p1:id="@+id/pos20"
p1:layout_width="0dp"
p1:layout_height="fill_parent"
p1:layout_weight="1"
tools:visibility="visible"
p1:scaleType="centerInside"
p1:background="@android:color/transparent" />
<Button xmlns:tools="http://schemas.android.com/tools"
p1:id="@+id/pos21"
p1:layout_width="0dp"
p1:layout_height="fill_parent"
p1:layout_weight="1"
tools:visibility="visible"
p1:scaleType="centerInside"
p1:background="@android:color/transparent" />
<Button xmlns:tools="http://schemas.android.com/tools"
p1:id="@+id/pos22"
p1:layout_width="0dp"
p1:layout_height="fill_parent"
p1:layout_weight="1"
tools:visibility="visible"
p1:scaleType="centerInside"
p1:background="@android:color/transparent" />
</LinearLayout>
</LinearLayout>
<Button
p1:text="Voltar"
p1:layout_width="match_parent"
p1:layout_height="wrap_content"
p1:id="@+id/btnVoltar"
p1:layout_gravity="bottom"
p1:textSize="20dp"
p1:layout_marginLeft="5dp"
p1:layout_marginRight="5dp"
p1:layout_weight="0" />
</LinearLayout>
任何想法如何解決它?
PS:兩個星期前開始Xamarin,所以對我來說一些編碼的缺點是beeing有點難=/
謝謝!
編輯 - 解決方案:
我遵循jzeferino提示,並研究了一些。即使在他的小竅門之後,佈局仍然不盡如人意。所以我意識到問題出在狀態欄高度。改變我的佈局一些小問題之後,所有我所要做的就是創建一個方法來獲得,並返回其高度
public int getStatusBarHeight()
{
int statusBarHeight = 0;
int resourceId = Resources.GetIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0)
{
statusBarHeight = Resources.GetDimensionPixelSize(resourceId);
}
return statusBarHeight;
}
爲了在下面的行janela.ShowAsDropDown(popup, Android.Views.ViewGroup.LayoutParams.MatchParent, tam);
凡int tam = getStatusBarHeight();
而且使用它作爲一個參數最終結果是this one
您需要發佈模式的佈局來代替。 – jzeferino
我做了...第一個圖像是我對模態的佈局 –
我在說的是代碼。 – jzeferino