gpt4 book ai didi

android - 如何制作半屏显示的Activity?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:38:29 72 4
gpt4 key购买 nike

我想做一个显示在半屏上的 Activity (就像对话框但不是对话框)我想在上面添加一些文本、开关按钮和标签?

我试过对话框,但它不能满足我,所以现在我想调整 Activity 的大小。 帮助

提前致谢

最佳答案

简单。就用 fragment 吧!使用 fragment ,您将完全控制所有内容的大小和位置。看我的例子

这是我的主要 xml。这是两个独立的 fragment 。每个占据大约四分之一的屏幕。

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
android:padding="12dp">

<fragment
android:name="com.diamond.home.fragments.TopFragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>

<!-----here, add the rest of your xml for your main activity -------->

将显示这些 fragment 的主要 Activity 不需要执行任何操作来显示您的 fragment ,因为您的 XML 已经为您调用了这些 fragment 。注意:如果您只想在特定时间显示 fragment ,您可以从 xml 中引用 fragment,并将可见性设置为 GONE。然后当你需要它时,将它设置为 VISIBLE。

然后,像这样创建 fragment 类:

 public class TopFragment extends Fragment {


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragments_top, container, false);
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

//do your stuff for your fragment here


}

因此您还需要为顶部 fragment 创建另一个 xml 布局。在那里,您可以添加按钮、 TextView 或您拥有的东西。希望这可以帮助。如果您有任何问题随时问。

关于android - 如何制作半屏显示的Activity?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24245785/

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