2017-09-16 128 views
1

我已將ImageView和兩個TextField添加到我的佈局中,但是當我在預覽中查看時,它只是保持空白。它給我錯誤「渲染錯誤」。我能做什麼?在你的根佈局佈局保持空白

<?xml version="1.0" encoding="utf-8"?> 
<RealtiveLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/colorSlide_1" > 

<ImageView 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:src="@drawable/wireless" 
    android:layout_centerHorizontal="true" 
    android:scaleType="centerCrop" 
    android:layout_marginTop="150dp" 
    android:id="@+id/img" 
    /> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:text="@string/slide_1_title" 
    android:textColor="android:color/white" 
    android:textSize="30sp" 
    android:textStyle="bold" 
    android:gravity="center_horizontal" 
    android:layout_below="@+id/img" 
    android:layout_marginTop="12dp" 
    android:id="@+id/slide_title" 
    /> 
<TextView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:text="@string/slide_1_desc" 
    android:textColor="android:color/white" 
    android:textSize="18sp" 
    android:gravity="center_horizontal" 
    android:layout_below="@id/slide_title" 
    android:layout_marginTop="12dp" 
    android:id="@+id/slide_desc" 
    android:layout_marginRight="40sp" 
    android:layout_marginLeft="40sp" 
    /> 

</RealtiveLayout> 
+0

@NileshRathod因爲我還沒有與Android工作室工作但我需要知道我能做到這一點? – MIsterX

回答

1

檢查下面這樣的變化:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/colorSlide_1" 
> 

<ImageView 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:src="@drawable/wireless" 
    android:layout_centerHorizontal="true" 
    android:scaleType="centerCrop" 
    android:layout_marginTop="150dp" 
    android:id="@+id/img" 
    /> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="45dp"//or you use wrap_content 
    android:text="@string/slide_1_title" 
    android:textColor="android:color/white" 
    android:textSize="30sp" 
    android:textStyle="bold" 
    android:gravity="center_horizontal" 
    android:layout_below="@+id/img" 
    android:layout_marginTop="12dp" 
    android:id="@+id/slide_title" 
    /> 
<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/slide_1_desc" 
    android:textColor="android:color/white" 
    android:textSize="18sp" 
    android:gravity="center_horizontal" 
    android:layout_below="@id/slide_title" 
    android:layout_marginTop="12dp" 
    android:id="@+id/slide_desc" 
    android:layout_marginRight="40sp" 
    android:layout_marginLeft="40sp" 
    /> 

</RelativeLayout> 
+0

你能幫我第二次嗎?當我啓動這個應用程序時,它給了我一個錯誤的行:Android:textColor =「Android:color/White我該如何解決這個問題?」 – MIsterX

+0

使用像這樣的android:textColor =「@ android:color/white」... 如果你存儲在你的項目的顏色文件,那麼你使用android:textColor =「@ color/white」 –

+0

感謝它解決了 – MIsterX

1

變化RealtiveLayoutRelativeLayout

我會添加以下我的佈局文件。

+0

ooops ...你是對的。但我的第二個文本字段仍然不顯示。做ypu knwo如何解決? – MIsterX

+0

在您的代碼中將您的'TextView'的寬度更改爲'android:layout_height =「wrap_content」'@ MIsterX – KeLiuyue

+0

更改您的代碼中TextView的高度@ MIsterX – KeLiuyue