简体   繁体   English

如何居中隐藏按钮

[英]how to center invisible Button

i'm trying to make (try again) button in center this button is invisible , i already tried to put : android:layout_gravity="center" but doesn't work any suggestions for resolve this problems This what he give me : 我试图使(再试) button在中间这个button是看不见的,我已经尝试过把: android:layout_gravity="center" ,但对于解决不工作的任何建议,这个问题这是他给我的:

图片以获取更多描述

My XML file : 我的XML文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#ffff"
android:id="@+id/activity_viewsol">
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linear"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar_top"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="@color/colorPrimary"
    app:theme="@style/ThemeOverlay.AppCompat.Light"
    android:fitsSystemWindows="true"
    app:layout_collapseMode="pin"
    android:elevation="5dp"
    app:navigationIcon="@drawable/ic_back"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textColor="#ffffff"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="48sp"
        android:textStyle="bold"
        android:text="Solution"
        android:id="@+id/toolbar_title" />
</android.support.v7.widget.Toolbar>
</RelativeLayout>

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:id="@+id/scrollview"
    android:stackFromBottom="true"
    android:scrollbarSize="10dp"
    android:scrollbarThumbVertical="@drawable/scrollbar"
    android:transcriptMode="alwaysScroll">
    <LinearLayout
        android:id="@+id/All_Layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_margin="6dp"
        android:padding="15dp">
        <TextView
            android:typeface="normal"
            android:layout_gravity="center"
            android:id="@+id/prob"
            android:textStyle="bold"
            android:textColor="#383838"
            android:gravity="center"
            android:textSize="45sp"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_marginBottom="8dp"
            android:layout_weight="1" />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:layout_marginBottom="20dp">
            <View
                android:layout_height="1dp"
                android:layout_width="500dp"
                android:background="#000"
                android:layout_gravity="center"/>
            <TextView
                android:layout_marginStart="10dp"
                android:layout_marginEnd="10dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="O"
                android:textSize="40sp"
                android:textColor="@color/colorAccent"
                android:textStyle="bold"
                android:layout_gravity="center"/>
            <View
                android:layout_height="1dp"
                android:layout_width="500dp"
                android:background="#000"
                android:layout_gravity="center" />
        </LinearLayout>
        <TextView
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="35sp"
            android:textStyle="normal"
            android:textColor="#383838"
            android:id="@+id/sol"
            android:typeface="normal"
            android:layout_marginBottom="20dp"/>
        <View
            android:id="@+id/LineHorizontalTwo"
            android:layout_height="1dp"
            android:layout_width="1000dp"
            android:background="#000"
            android:layout_gravity="center"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal">
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:layout_margin="20dp"
            android:layout_gravity="start|center"
            android:id="@+id/Like"
            android:src="@mipmap/ic_like"
            />
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:layout_margin="20dp"
            android:layout_gravity="end|center"
            android:id="@+id/sharesol"
            android:src="@mipmap/ic_action_share"/>
    </LinearLayout>
    </LinearLayout>

</ScrollView>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableTop="@mipmap/retry"
    android:drawablePadding="10dp"
    android:layout_gravity="center"
    android:gravity="center"
    android:visibility="gone"
    android:id="@+id/retry"
    android:onClick="onClickRetry"
    android:background="@null"
    android:padding="6dp"
    android:textSize="35sp"
    android:text="TRY AGAIN"
    android:textColor="#000" />
    </LinearLayout>
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"/>

also you need a RelativeLayout for parent of this tag 您还需要此标签的父级的RelativeLayout

You can do it simply doing by enclosing your error button inside the Relative Layout as following steps: 您可以通过将“错误”按钮包含在“相对布局”中的简单步骤来做到这一点:

  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">
     <Button
        android:id="@+id/retry"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@null"
        android:drawablePadding="10dp"
        android:drawableTop="@drawable/ic_android"
        android:gravity="center"
        android:padding="6dp"
        android:text="TRY AGAIN"
        android:textColor="#000"
        android:textSize="35sp"
        android:visibility="visible" />
</RelativeLayout>

Make the parent layout as RelativeLayout and put everything inside RelativeLayout except the button. 将父布局设置为RelativeLayout然后将除按钮之外的所有内容都放入RelativeLayout use 采用

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!--Put your other codes here-->
    <!--everything can be within LinerarLayout-->



    <Button
        android:id="@+id/retry"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@null"
        android:drawablePadding="10dp"
        android:drawableTop="@mipmap/retry"
        android:onClick="onClickRetry"
        android:padding="6dp"
        android:text="TRY AGAIN"
        android:textColor="#000"
        android:textSize="35sp"
        android:visibility="gone" />

</RelativeLayout>

as your button code 作为您的按钮代码

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM