gpt4 book ai didi

android RelativeLayout 如何获得更小尺寸的窗口

转载 作者:太空狗 更新时间:2023-10-29 13:40:39 27 4
gpt4 key购买 nike

我无法让 Theme.Dialog Activity 变小。
问题是我只想要一半的高度。
看下面的图片。

这是 list :

 <activity android:name=".PopUpSettings" 
android:label="@string/app_name"
android:theme="@android:style/Theme.Dialog"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation">

这是 xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingBottom="15dp"
>

<com.hellberg.ptppservice.imageedit.ColorPicker
android:id="@+id/color_picker_popup_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
/>

<TextView android:id="@+id/exampeltext_popup_settings"
android:text = "This is the best app in the world"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/color_picker_popup_settings"
/>

<Button android:id="@+id/fontleft_button_popup_settings"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
/>

<Button android:id="@+id/fontright_button_popup_settings"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
/>

<TextView android:id="@+id/textlogo_popup_settings"
android:text = "©2011"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>

这是屏幕:

Here is the screen

最佳答案

这会做你想做的。请注意,您将获得完整的窗口高度,因此除以 2 不会使其恰好减半。我试过你的布局除以 3,看起来不错。

public class DialogExampleActivity extends Activity {   

private int mWindowHeight;

private static final int DIALOG_OPEN = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Display display = getWindowManager().getDefaultDisplay();
mWindowHeight = display.getHeight();

showDialog(DIALOG_OPEN);
}

@Override
protected Dialog onCreateDialog(int id) {
Dialog myDialog = new Dialog(DialogExampleActivity.this);

switch (id) {
case DIALOG_OPEN:
myDialog.setContentView(R.layout.my_dialog);
myDialog.setCancelable(true);

RelativeLayout rr = (RelativeLayout) myDialog.findViewById(R.id.relative_layout);
LayoutParams params = rr.getLayoutParams();
params.height = mWindowHeight / 3;
rr.setLayoutParams(params);

return myDialog;
}

return null;
}
}

关于android RelativeLayout 如何获得更小尺寸的窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6168102/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com