2016-05-10 17 views
0

私のコードを投稿しています。私は垂直方向の相対レイアウトを使用しています。android:layout_belowがRelativeLayoutで動作しません

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Next" 
    android:id="@+id/next" 
    android:layout_marginTop="170dp" 
    android:layout_alignParentRight="true"/> 
<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Previous" 
    android:id="@+id/previous" 
    android:layout_marginTop="170dp" 
    android:layout_alignParentLeft="true" /> 

<TextView 
    android:id="@+id/day" 
    android:textStyle="bold" 
    android:textSize="30dp" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="20dp"/> 

<ImageView 
    android:id="@+id/product_image" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="-50dp"/> 

<TextView 
    android:id="@+id/description" 
    android:text="test" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:textSize="18dp" 
    android:layout_below="@id/product_image" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="5dp"/> 
+4

を? – NoChinDeluxe

+0

'ReletiveLayout'には' orientation'は 'LinearLayout'だけありません – cyroxis

答えて

1

相対レイアウトでは、すべてのビューに少なくとも1つのアンカーが必要です。あなたのイメージビューには何もありません。また、日のビューもありません。彼らはお互いや親のビューにアンカーすることができます。これを指定しないと、フレームビューのように動作し、左上に固定されます。レイアウトのマージンに頼るのではなく、ビュー間をパディングすることをお勧めします。マイナスマージンは一般的には本当に悪い考えです。

このような何か試してみてください:何を意味 "動作しない" ん

<TextView 
android:id="@+id/day" 
android:textStyle="bold" 
android:textSize="30dp" 
android:layout_width="wrap_content" 
android:layout_height="match_parent" 
android:layout_centerHorizontal="true" 
android:layout_alignParentTop="true" 
android:layout_marginTop="20dp"/> 

<ImageView 
android:id="@+id/product_image" 
android:layout_width="fill_parent" 
android:layout_height="match_parent" 
android:layout_below="@id/day" 
android:layout_centerHorizontal="true" /> 

<TextView 
android:id="@+id/description" 
android:text="test" 
android:layout_width="wrap_content" 
android:layout_height="match_parent" 
android:textSize="18dp" 
android:layout_below="@id/product_image" 
android:layout_marginLeft="10dp" 
android:layout_marginRight="5dp"/> 

<Button 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Next" 
android:id="@+id/next" 
android:layout_below="@id/description" 
android:align_parentBottom="true" 
android:layout_alignParentRight="true"/> 

<Button 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Previous" 
android:id="@+id/previous" 
android:layout_below="@id/description" 
android:align_parentBottom="true" 
android:layout_alignParentLeft="true" /> 
関連する問題