2016-07-22 5 views
0

Androidスタジオプロジェクトで作業しています。画面の下部にFragmentを追加します。これまでのところうまくいきました、それは働き、示されています。しかし、私が一番上にRelativeLayoutを表示したい場合、エミュレータには表示されませんが、Android Studioのデバイス画面に表示されます。画面の上部にのみ背景を作成するレイアウトが必要です。私のコードに間違いがありますか、あるいは背景を作成する他の方法がありますか?RelativeLayoutはAndroidStudioのDevicescreenに表示されますが、エミュレータでは表示されません

これは私のXMLコードです:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:weightSum="1" 
    android:background="#000"> 

    <fragment 
     android:id="@+id/fragment1" 
     android:name="com.htlhl.listfragment.MyListFragment" 
     android:layout_width="match_parent" 
     android:layout_height="197dp" 
     android:layout_alignParentBottom="true" /> 
    <!--The following RelativeLayout is not shown at the top--> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:id="@+id/relativeLayout" 
     android:background="#00632e" 
     android:focusable="true"> 

     <TextView 
      android:layout_width="250dp" 
      android:layout_height="30dp" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:text="Medium Text" 
      android:gravity="center" 
      android:textColor="#000" 
      android:background="#fff" 
      android:id="@+id/textView2" 
      android:layout_centerVertical="true" 
      android:layout_centerHorizontal="true" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      style="?android:attr/buttonBarButtonStyle" 
      android:layout_alignParentRight="true" 
      android:layout_centerHorizontal="true" 
      android:text="Start" 
      android:textColor="#fff"/> 

    </RelativeLayout> 

</RelativeLayout> 

のAndroidメーカー:

Android Studio

エミュレータと実際のデバイス:

Emulator

+1

は、には、Android Studioとデバイスの両方からのスクリーンショットを、提供することはできますか?投稿を編集して詳細情報を追加することができます。 –

+0

私はこれを実際のデバイス(Moto G 2)で実行しようとしました。 エミュレータにはまったく依存しません。実際のデバイスでこれをテストしてみてください。 –

+0

ありがとう、Maniya Joe、私はそれを試してみましょう。動作していない場合は、Aleksandarのスクリーンショットを投稿します – Goetti

答えて

0

これを試してみてください。

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="#000"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:id="@+id/relativeLayout" 
     android:background="#00632e" 
     android:focusable="true"> 

     <TextView 
      android:layout_width="250dp" 
      android:layout_height="30dp" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:text="Medium Text" 
      android:gravity="center" 
      android:textColor="#000" 
      android:background="#fff" 
      android:id="@+id/textView2" 
      android:layout_centerVertical="true" 
      android:layout_centerHorizontal="true" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      style="?android:attr/buttonBarButtonStyle" 
      android:layout_alignParentRight="true" 
      android:layout_centerHorizontal="true" 
      android:text="Start" 
      android:textColor="#fff"/> 

    </RelativeLayout> 

    <fragment 
     android:id="@+id/fragment1" 
     android:name="com.htlhl.listfragment.MyListFragment" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" /> 

</LinearLayout> 

さらにレイアウトを改善することができます。これが機能するかどうか教えてください。 TextViewの程度

+0

ありがとうございましたが、今は本当に間違いを発見しました。私のcontent_main.xmlファイルで、レイアウトはトップにあります。 content_main.xmlはactivity_main.xmlに含まれています - >しかし、includeはツールバーの下ではなく画面の上部で始まるので、探しているレイアウトはツールバーの後ろにあります。ツールバーの下にicludeを移動するにはどうすればよいですか? – Goetti

+0

の親レイアウトがCoordinatorLayoutの場合は、それ自体で処理します(問題は存在してはいけません)。私はあなたが静的なDPに次元を設定しているので、おそらくあなたの携帯電話にすべての要素を表示するのに十分なスペースがないことを推測している。 –

+0

@Goetti、また、私のレイアウトを試してみてください。そうしないと、試してみる価値があります。 –

0
<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="50dp" 
android:layout_alignParentTop="true" 
android:background="#00632e" 
android:baselineAligned="false" 
android:weightSum="1.0"> 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_weight="0.8" 
    android:layout_height="match_parent" 
    android:layout_gravity="center_vertical"> 
    <TextView 
     android:layout_width="200dp" 
     android:layout_height="30dp" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:text="Medium Text" 
     android:gravity="center" 
     android:layout_gravity="center_vertical" 
     android:textColor="#000" 
     android:background="#fff" 
     android:id="@+id/textView2" /> 
</LinearLayout> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="0.2"> 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      style="?android:attr/buttonBarButtonStyle" 
      android:text="Start" 
      android:gravity="center" 
      android:textColor="#fff" /> 
    </LinearLayout> 

</LinearLayout> 

その...

関連する問題