简体   繁体   English

将按钮移动到半透明布局的右上角位置

[英]Move button to top-right position in translucent layout

I want to move my button at top-right position on my activity. 我想将按钮移动到活动的右上角。

In my layout, the button is on top-right position, but when I start activity it appears in center vertically. 在我的布局中,按钮位于右上角,但是当我开始活动时,它会垂直居中显示。

Here's my layout code: 这是我的布局代码:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainClass" >

    <Button 
        android:id="@+id/button1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true" 
        android:layout_alignParentTop="true" 
        android:text="UL" />
</RelativeLayout>

Here's my styles.xml code: 这是我的styles.xml代码:

<resources>
    <style name="AppBaseTheme" parent="android:Theme.Light">
    </style>
    <style name="AppTheme" parent="AppBaseTheme">
    </style>
    <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>
</resources>

And finally here's my Activity code: 最后是我的活动代码:

package com.test.app;

import android.os.*;
import android.view.*;
import android.app.*;

public class MainClass extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {        
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main_layout);
    }
}

screenshot: 屏幕截图: 在此处输入图片说明

I tried your code only and the button is appearing on top right. 我只尝试了您的代码,该按钮显示在右上角。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:text="Button" />

Layout is okey. 布局不错。 Make change in style.xml as below. 如下更改style.xml。

<resources>
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
<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">false</item>
    <item name="android:backgroundDimEnabled">false</item>
</style>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将布局中心放在另一个布局的右上角? - How to place center of layout on top-right corner of another layout? 如何在 CardView 的右上角 position 上放置一个图标? - How do I place an icon on top-right position of CardView? 如何在父母布局的右上角添加两个浮动操作按钮(一半为内部布局,一半为外部),并在单击时显示 - How to add two floating action button on top-right of parrent layout (half insidelayout, and half outside), and show on click 图片右上角的动态十字按钮将其删除 - dynamic cross button on top-right of image to delete it 将 ImageView 中的图像与右上角对齐 - Aligning an image in an ImageView to the top-right corner 将标签放在右上角 - Putting a label on the top-right corner 是否可以将按钮作为图层放置在表格布局的顶部? - Is it possible to position a button on top of a table layout as a layer? 如果进行了编辑,Android Designer会将元素移到右上角 - Android designer moves elements to the top-right if edited 我如何将相对布局中的视图与右上角对齐 - How do i align a view in RelativeLayout to top-right corner Popupwindow:ShowAsDropDown是右上角而不是左下角? - Popupwindow: ShowAsDropDown as top-right instead of bottom-left?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM