有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java My XML文件不显示任何内容

我不明白为什么显示屏上什么也没出现。我可以看到按钮和ImageView(Zauber),但除此之外什么都看不到。。有人能帮我吗

<FrameLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
安卓:orientation="vertical"
安卓:layout_width="fill_parent"
安卓:layout_height="fill_parent"
安卓:background="@color/halbtransparent">


    <ImageView
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        app:srcCompat="@drawable/dialoghintergrund"
        安卓:id="@+id/willdialog"
        安卓:layout_margin="20dp" />


    <ImageView
        安卓:scaleType="fitXY"
        安卓:id="@+id/zauberer"
        安卓:layout_marginTop="40dp"
        安卓:layout_marginLeft="50dp"
        安卓:layout_marginStart="50dp"
        app:srcCompat="@drawable/zaubererdialoghg"
        安卓:layout_height="55dp"
        安卓:layout_width="43dp" />

    <ImageButton
        安卓:id="@+id/btn_verstanden"
        安卓:scaleType="fitXY"
        安卓:layout_width="130dp"
        安卓:layout_marginTop="410dp"
        安卓:layout_gravity="center_horizontal"
        安卓:background="#00000000"
        安卓:layout_height="50dp"
        app:srcCompat="@drawable/btn_verstanden"/>


共 (3) 个答案

  1. # 1 楼答案

    几点建议:

    1. fill_parent不推荐使用match_parent

    2. android:src代替app:srcCompat

    3. 您使用的是静态Dp值android:layout_marginTop="410dp",它将根据像素密度在不同的设备中变化

    使用layout_weightweightSumadJustViewBoundsGravity来对齐视图

    1. mdpihdpixhdpi等文件夹中使用不同大小drawable的最佳实践

    试试这个:

    <LinearLayout 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="@color/colorPrimary"
        android:orientation="vertical">
    
    
        <ImageView
            android:id="@+id/willdialog"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="20dp"
            android:src="@mipmap/ic_launcher" />
    
    
        <ImageView
            android:id="@+id/zauberer"
            android:layout_width="43dp"
            android:layout_height="55dp"
            android:layout_marginLeft="50dp"
            android:layout_marginStart="50dp"
            android:layout_marginTop="40dp"
            android:scaleType="fitXY"
            android:src="@mipmap/ic_launcher" />
    
        <ImageButton
            android:id="@+id/btn_verstanden"
            android:layout_width="130dp"
            android:layout_height="50dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="100dp"
            android:background="#00000000"
            android:scaleType="fitXY"
            android:src="@mipmap/ic_launcher" />
    
    </LinearLayout>
    
  2. # 2 楼答案

    Activity或Android Studio中没有显示任何内容?你关闭了Framelayout标签了吗?尝试使用Relativelayout。确保你的setContentView中有Activity

  3. # 3 楼答案

    之所以会出现这种情况,是因为FrameLayout中的子布局相互重叠,并且底部写入的子布局被绘制在其他布局之上。使用“方向”设置为“垂直”的LinearLayout来解决问题