【问题标题】:How to create android activity that shows at specified screen position?如何创建显示在指定屏幕位置的 android 活动?
【发布时间】:2011-07-08 21:49:13
【问题描述】:

我当前的布局显示的活动不是全屏(没关系)。

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="100dip"
android:layout_height="200dip" >

<TextView android:layout_height="wrap_content" android:id="@+id/textView1"
    android:layout_width="fill_parent" android:text="@string/hello"></TextView>

我还添加了 android:theme="@android:style/Theme.Translucent" 来体现我的活动。

我的 200x100dip 活动现在显示在左上角。如何指定线性布局(或活动)的位置?

【问题讨论】:

    标签: android android-activity position


    【解决方案1】:

    您可以使用FrameLayoutRelativeLayout 作为最外层的布局。 Ant 然后使用 dp 或 android:layout_centerInParent 或类似的绝对位置。

    【讨论】:

    • 我把最外层的布局改成了相对布局,dp中的位置我可以用哪个参数?
    【解决方案2】:

    我相信您的 Activity 的最外层布局元素 (LinearLayout) 将放置在一个 FrameLayout 中,该 FrameLayout 是 Android 提供的父级。我建议你让你的最外层布局 match_parent/fill_parent 在 layout_height 和 _width 中,然后在你的最外层布局上使用gravity="center" 将其中的内容居中。通过让最外面的布局是透明的并且不捕获点击元素,它将显示为中间的布局,后面的元素是可见的。如果我猜对了,这就是你想要在这里实现的目标。

    【讨论】:

      【解决方案3】:

      将该布局放在另一个绝对布局中,您可以在其中使用 android:layout_width="fill_parent" 和 android:layout_height="fill_parent" 您可以做的另一件事是使用它:http://www.droiddraw.org/ 您可以使用它手动移动元素,它会为您提供用于执行此操作的 XML 代码。我发现它在 android 中布局 XML 非常有用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-12-26
        • 2021-04-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-27
        • 2016-04-05
        • 1970-01-01
        相关资源
        最近更新 更多