首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >透明主题将项目置于中心

透明主题将项目置于中心
EN

Stack Overflow用户
提问于 2012-10-03 22:34:24
回答 1查看 210关注 0票数 1

我想创建一个除了网格视图和文本视图之外的主要透明的活动,所以我的风格是:

代码语言:javascript
运行
复制
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>

和我的布局:

代码语言:javascript
运行
复制
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView ... android:layout_gravity="bottom" />

<GridView ...
    android:layout_gravity="bottom"
 />

然而,文本视图和网格视图恰好在中心,忽略了我的底部布局重力...

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-03 23:03:44

LinearLayout无法做到这一点,请改用RelativeLayoutRelativeLayout将使您能够访问它的子级中的centerInParent属性。

这里:

代码语言:javascript
运行
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >


    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true">  //<---- this here is the trick
        <TextView ... 
            android:layout_gravity="bottom" />
        <GridView ...
            android:layout_gravity="bottom"
        />
    </LinearLayout>

</RelativeLayout>

你也许可以去掉那个LinearLayout,我建议你把它弄乱。这取决于您需要视图的外观。

无论哪种方式,RelativeLayoutlayout_centerInParent都应该做您想做的事情。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12710733

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档