Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我的XML文件不显示任何内容_Java_Android_Android Layout - Fatal编程技术网

Java 我的XML文件不显示任何内容

Java 我的XML文件不显示任何内容,java,android,android-layout,Java,Android,Android Layout,我不明白为什么显示器上什么也没有出现。我可以看到按钮和图像视图(Zauber),但除此之外什么也看不到。。有人能帮我吗 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="fill_paren

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

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


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


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

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


活动
或Android Studio中没有显示任何内容?您是否关闭了
Framelayout
标记?尝试使用
Relativelayout
。确保您的
活动中有
setContentView
活动或Android Studio中没有显示任何内容?您是否关闭了
Framelayout
标记?尝试使用
Relativelayout
。确保在
活动中有
setContentView

这是因为FrameLayout中的子布局相互重叠,并且底部写入的子布局绘制在其他布局之上。使用方向设置为垂直的LinearLayout解决此问题。

这是因为FrameLayout中的子布局相互重叠,并且底部写入的子布局绘制在其他布局之上。使用方向设置为垂直的线性布局来解决问题。

两个建议:

  • fill\u parent
    不推荐使用
    match\u parent

  • 使用
    android:src
    而不是
    app:srcCompat

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

  • 使用
    layout\u weight
    weightSum
    adJustViewBounds
    Gravity
    对齐视图

  • mdpi
    hdpi
    xhdpi
    等文件夹中使用不同大小的
    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>
    
    
    
    几点建议:

  • fill\u parent
    不推荐使用
    match\u parent

  • 使用
    android:src
    而不是
    app:srcCompat

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

  • 使用
    layout\u weight
    weightSum
    adJustViewBounds
    Gravity
    对齐视图

  • mdpi
    hdpi
    xhdpi
    等文件夹中使用不同大小的
    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>
    
    
    
    我认为您的问题是
    srcCompat
    正如在这个链接中所说的,我认为您的问题是
    srcCompat
    正如在这个链接中所说的,好的,谢谢!当我现在使用android:src时,我必须将Java活动中的“AppCombatActivity”更改为“Activity”吗?或者这没有关系?没有必要…当我想将android:background更改为android:src时,您仍然可以在code中使用
    AppCompatActivity
    ,在我的xml中是背景透明的
    android:src
    用于imageview或imagebuttons。。。如果你想设置transperant背景,请使用:
    android:background=“@android:color/transparent”
    好的,谢谢!当我现在使用android:src时,我必须将Java活动中的“AppCombatActivity”更改为“Activity”吗?或者这没有关系?没有必要…当我想将android:background更改为android:src时,您仍然可以在code中使用
    AppCompatActivity
    ,在我的xml中是背景透明的
    android:src
    用于imageview或imagebuttons。。。如果要设置transperant背景,请使用:
    android:background=“@android:color/transparent”