按钮在移动设备上的外观与在android studio布局视图中不同

问题描述 投票:0回答:1

我已经使用相同的可绘制背景文件“ find_button.xml”定义了三个按钮。由于某些原因,“启动服务器活动”按钮(id =“ start_button”)忽略文件“ find_button.xml”。我找不到任何错误。.

Android Studio中的布局视图:

Layout view in android studio

手机上的布局视图:

Layout View on mobile

xml布局文件:

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    android:background="#1A91C6"
    tools:context=".ServerInitial">


    <Button
        android:id="@+id/start_button"

        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_marginStart="24dp"
        android:layout_marginLeft="24dp"
        android:layout_marginEnd="24dp"
        android:layout_marginRight="24dp"
        android:layout_marginBottom="24dp"
        android:background="@drawable/find_button"
        android:backgroundTint="#DCB235"
        android:onClick="startServerActivity"
        android:text="@string/start_server_button"
        android:textColor="#FFFFFF"
        android:textSize="25sp"
        app:layout_constraintBottom_toTopOf="@+id/close_button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <ListView
        android:id="@+id/peers_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginStart="24dp"

        android:layout_marginLeft="24dp"
        android:layout_marginTop="24dp"
        android:layout_marginEnd="24dp"
        android:layout_marginRight="24dp"
        android:layout_marginBottom="24dp"
        android:cacheColorHint="?android:attr/colorMultiSelectHighlight"
        android:visibility="visible"
        app:layout_constraintBottom_toTopOf="@+id/start_button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/find_button">


    </ListView>

    <Button
        android:id="@+id/find_button"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_marginStart="24dp"
        android:layout_marginLeft="24dp"
        android:layout_marginTop="24dp"
        android:layout_marginEnd="24dp"
        android:layout_marginRight="24dp"
        android:background="@drawable/find_button"
        android:backgroundTint="#DCB235"
        android:drawableLeft="@drawable/ic_search_black_72dp"
        android:gravity="left|center_vertical"
        android:onClick="sucheGeräte"
        android:text="@string/suchen_button"
        android:textColor="#FFFFFF"
        android:textSize="25sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/close_button"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_marginStart="24dp"
        android:layout_marginLeft="24dp"
        android:layout_marginEnd="24dp"
        android:layout_marginRight="24dp"
        android:layout_marginBottom="32dp"
        android:background="@drawable/find_button"
        android:backgroundTint="#E3931D"
        android:onClick="closeConnection"
        android:text="@string/close_connection"
        android:textColor="#FFFFFF"
        android:textSize="25sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

可绘制背景文件“ find_button.xml”

    <?xml vers`enter code here`ion="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners
        android:radius="20dp" />
</shape>
android android-studio button view
1个回答
0
投票

您的代码没有错。尝试一次重新安装您的应用程序,它应该可以正常工作。如果它不尝试使android studio中的缓存无效并重新启动选项,然后安装/运行您的应用。我在物理设备以及仿真器中尝试了相同的代码,这是输出。Physical Device

Emulator

© www.soinside.com 2019 - 2024. All rights reserved.