android模拟器显示与预览不同

时间:2015-12-17 13:43:34

标签: android emulation

今天我遇到了一些模拟器的奇怪行为,我不知道如何修复它。

我正在阅读一些关于如何创建音频播放器的教程。在我的预览中,它看起来像: enter image description here

然而,当我启动模拟器(设置为相应的参数:Nexus 5.7“,1440x2560:560dpi,api 21)时,它看起来像这样: enter image description here

完全不一样。

这可能是什么原因? 这是代码没有在预览中反映出来的,还是我在选择/配置模拟器时搞砸了?

修改

Here是教程。

EDIT2

player.xml:

<?xml version="1.0" encoding="utf-8"?>
<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:background="#636363"
    tools:context=".MainActivity">

    <!-- Nagłówek playera !-->
    <LinearLayout
        android:orientation="horizontal"
        android:id="@+id/player_header"
        android:layout_width="match_parent"
        android:layout_height="60dip"
        android:background="@drawable/bg_player_header"
        android:layout_alignParentTop="true"
        android:paddingLeft="5dp"
        android:paddingRight="5dp">

        <!-- Tytuł piosenki !-->
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textColor="#04b3d2"
            android:textSize="16sp"
            android:text="@string/title_song"
            android:paddingStart="10dp"
            android:paddingEnd="0dp"
            android:textStyle="bold"
            android:layout_marginTop="10dp"
            />

        <!-- Playlist button !-->
        <ImageButton
            android:contentDescription="@string/playlist_open"
            android:id="@+id/songTitle"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/btn_playlist"
            android:background="@null"/>

    </LinearLayout>

    <!-- Miniaturka dla piosenki !-->
    <LinearLayout
        android:orientation="horizontal"
        android:id="@+id/songThumbnail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:gravity="center"
        android:layout_below="@+id/player_header">

            <ImageView
                android:contentDescription="@string/song_thumnail"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:maxHeight="260dp"
                android:src="@drawable/footer"/>

    </LinearLayout>

    <!-- Player Footer -->
    <LinearLayout
        android:id="@+id/player_footer_bg"
        android:layout_width="match_parent"
        android:layout_height="130dp"
        android:layout_alignParentBottom="true"
        android:background="@drawable/bg_player_footer"
        android:gravity="center">

        <!-- Przyciski !-->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_gravity="center_vertical"
            android:background="@drawable/rounded_corner"
            android:paddingLeft="10dp"
            android:paddingRight="10dp">

            <!-- Poprzedni !-->
            <ImageButton
                android:contentDescription="@string/previous_song"
                android:id="@+id/btnPrevious"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/img_btn_previous"
                android:background="@null"
                android:layout_gravity="center_vertical"/>

            <!--  Wstecz !-->
            <ImageButton
                android:contentDescription="@string/backward_song"
                android:id="@+id/btnBackward"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/img_btn_backward"
                android:background="@null"
                android:layout_gravity="center_vertical"/>

            <!-- Play !-->
            <ImageButton
                android:contentDescription="@string/play_song"
                android:id="@+id/btnPlay"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/img_btn_play"
                android:background="@null" />

            <!-- Play !-->
            <ImageButton
                android:contentDescription="@string/forward_song"
                android:id="@+id/btnForward"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/img_btn_forward"
                android:background="@null"
                android:layout_gravity="center_vertical"/>

            <!-- Następny !-->
            <ImageButton
                android:contentDescription="@string/next_song"
                android:id="@+id/btnNext"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/img_btn_next"
                android:background="@null"
                android:layout_gravity="center_vertical"/>
        </LinearLayout>
    </LinearLayout>

    <!-- ProgressBar / SeekBar !-->
    <SeekBar
        android:id="@+id/songProgressBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/player_footer_bg"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginBottom="20dp"
        android:thumb="@drawable/seek_handler"
        android:progressDrawable="@drawable/seekbar_progress"
        android:paddingLeft="6dp"
        android:paddingRight="6dp"/>

    <!-- Timer -->
    <LinearLayout
        android:id="@+id/timerDisplay"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/songProgressBar"
        android:layout_marginRight="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginBottom="10dp">

        <!-- Obecny czas trwania !-->
        <TextView
            android:id="@+id/songCurrentDurationLabel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textColor="#eeeeee"
            android:textStyle="bold"
            android:gravity="start"
            android:text="0:00" />

        <!-- Całkowity czas trwania !-->
        <TextView
            android:id="@+id/sontTotallDurationLabel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="#04cbde"
            android:text="4:50"
            android:layout_weight="1"
            android:textStyle="bold"
            android:gravity="end"
            />
    </LinearLayout>


    <!-- Przyciski Powtórz i Mieszaj !-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/timerDisplay"
        android:gravity="center">

        <!-- Przycisk Powtórz !-->
        <ImageButton
            android:contentDescription="@string/repeat_song"
            android:id="@+id/btnRepeat"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/btn_repeat"
            android:layout_marginEnd="5dp"
            android:background="@null"/>

        <ImageButton
            android:id="@+id/btnShuffle"
            android:contentDescription="@string/shuffle_song"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/btn_shuffle"
            android:layout_marginStart="5dp"
            android:background="@null"
            />

    </LinearLayout>

</RelativeLayout>

2 个答案:

答案 0 :(得分:1)

好吧,我真的不知道为什么它不起作用。我创建了一个新的应用程序,我预览了一个工具栏

我把我的配置放在这里 - 与你的配置进行比较。首先,AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.piotr.myapplication"
          xmlns:android="http://schemas.android.com/apk/res/android">
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>
            </activity>
        </application>
    </manifest>

然后我的styles.xml文件:

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

最后main.xml布局(已空):

<?xml version="1.0" encoding="utf-8"?>
<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="com.example.piotr.myapplication.MainActivity">
</RelativeLayout>

希望你找到一个缺失的元素

答案 1 :(得分:0)

似乎是在Android Studio中预览您的活动只是一个没有工具栏的应用内容。

我很确定,您已经有两个xml布局文件 - 一个显示您的活动内容,另一个显示您的活动布局,bu可能只显示工具栏,因为内容仅包含在内

预计in布局管理器不要期望太多 - 它只能帮助您设计应用程序布局,但它不会给您带来作为模拟器或物理设备的直接体验。

你会在你的日常工作中发现一些类似的问题,例如:如果你想用RecyclerView制作应用程序,如天气应用程序Sunshine form Udacity课程(我强烈推荐你这门课程:开发Android应用程序)

如果您有任何疑问或者有些事情仍然不清楚,请随时提出

相关问题