![](/img/trans.png)
[英]How to make progressDrawable occupy entire width of seeker (Android)?
[英]How can I make a DialogFragment occupy the entire screen width
我試圖在onCreateView()和onViewCreated()中創建一個對話框,該對話框占據從舊AlertDialog構建器到新DialogFragment方法的整個屏幕寬度,以使顯示的對話框占據屏幕的整個寬度。 我當然可以獲取屏幕的寬度和高度值,但是無論我如何強制對話框使用這些值,它們都將被忽略。 無論方向如何,顯示的對話框始終具有相同的寬度。
在我最近的嘗試中,我有一個需要充氣的xml布局。 我需要使用自定義視圖,因此無法在xml中定義該視圖。 因此,我添加了它。
這是我在DialogFragment代碼中進行的最新嘗試。 當然,這只是我嘗試遵循帖子和Slidenerd視頻提示的眾多嘗試之一。
public class PopupDialog extends DialogFragment implements View.OnClickListener
{
private static final String TAG = PopupDialog.class.getName();
Button cancel = null;
Button focus = null;
View viewInput = null;
int width;
int height;
int id;
public PopupDialog()
{
}
public PopupDialog(View v, int id, int width, int height)
{
viewInput = v;
this.id = id;
this.width = width;
this.height = height;
}
@Override
public View onCreateView(LayoutInflater inflator, ViewGroup container, Bundle savedInstance)
{
Log.d(TAG, "onCreateView of DialogFragment called.");
View viewDialog = inflator.inflate(R.layout.popup_dialog, null);
// RelativeLayout relativeLayout = (RelativeLayout)viewDialog;
// LayoutParams params = new LayoutParams(width, height);
// relativeLayout.setLayoutParams(params);
// Point point = new Point();
// Activity activity = getActivity();
// activity.getWindowManager().getDefaultDisplay().getSize(point);
// if(point.x > point.y)
if(width > height)
{
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
else
{
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
ViewParent parent = viewInput.getParent();
if(parent != null)
{
Log.d(TAG, "View already present. Removing.");
((ViewGroup)parent).removeView(viewInput);
}
LayoutParams params = new LayoutParams(width, height);
viewInput.setLayoutParams(params);
((ViewGroup)viewDialog).addView(viewInput, 0);
cancel = (Button)viewDialog.findViewById(R.id.btn_cancel);
focus = (Button)viewDialog.findViewById(R.id.btn_focus);
cancel.setOnClickListener(this);
focus.setOnClickListener(this);
setCancelable(false);
return viewDialog;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
Log.d(TAG, "onViewCreated of DialogFragment called.");
//getDialog().getWindow().setLayout(LayoutParams.MATCH_PARENT, height);
getDialog().getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
WindowManager.LayoutParams wmlp = getDialog().getWindow().getAttributes();
wmlp.gravity = Gravity.TOP | Gravity.LEFT;
wmlp.x = 10; //x position
wmlp.y = 450 * (id) + 10;
// wmlp.width = width;
// wmlp.height = height;
}
我正在畫一個正弦波。 該視圖具有正確的大小,因為正弦波的范圍為0到12,但在橫向方向上,顯示的對話框僅占一半以上,因此看到0到6 +,然后必須等待從6到12繪制的wave進行循環,然后在返回0之前再次可見。我可以將對話框放在左上角。
有誰知道如何解決這個問題? 我去研究這個片段,是因為我被認為是罐裝AlertDialog方法的寬度是固定的,沒有人可以做。 我面臨着DialogFragment的相同限制。
嘗試在setContentView之后在create()方法上添加此代碼
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
我放棄了,並在ViewFlipper的ListView中創建了圖形。 不想要我想要,但是我得到了更多的房地產。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.