2016-01-30 26 views
2

我在我的一项活动中遇到了一些与布局有关的问题。以下是我目前有:将视图带到图像视图的前端 - Android XML

enter image description here

正如你所看到的,绿色的圆圈是头图像下面,即使它应该在顶部重叠。此外,正如您所看到的,圆圈右侧的文本位于标题图片下方,即使它应位于下方的一行中。

这是我目前的XML(我已经排除不相干的东西):

<ScrollView 
    android:id="@+id/scroll" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" > 

    <RelativeLayout 
     android:id="@+id/container" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="135dp" 
      android:id="@+id/headerImageView" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentStart="true" android:layout_alignParentLeft="true" 
      android:scaleType="centerCrop" 
      android:adjustViewBounds="false" 
      android:background="@drawable/header_image_test" /> 

     <Button 
      android:layout_width="49dp" 
      android:layout_height="49dp" 
      android:layout_alignBottom="@id/headerImageView" 
      android:layout_alignRight="@id/headerImageView" 
      android:layout_marginRight="8dp" 
      android:layout_marginBottom="8dp" 
      android:background="@drawable/star"/> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/headerImageView" 
      android:orientation="horizontal" 
      android:id="@+id/main_details_layout"> 

      <TextView 
       android:id="@+id/waitTimeTextView" 
       android:layout_width="90dp" 
       android:layout_height="90dp" 
       android:text="@string/wait_time_default" 
       android:layout_marginLeft="8dp" 
       android:layout_marginRight="16dp" 
       android:gravity="center" 
       android:background="@drawable/color0" 
       android:textColor="#FFFFFF" 
       android:layout_marginTop="-30dp" 
       android:textSize="30dp" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="60dp" 
       android:orientation="vertical"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="0.7" 
        android:text="Attraction Name" 
        android:textSize="23dp" 
        android:layout_marginRight="8dp" 
        android:gravity="bottom" 
        android:lines="1" 
        android:id="@+id/attractionNameTextView"/> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="Last Updated" 
        android:textSize="16dp" 
        android:layout_marginRight="8dp" 
        android:gravity="bottom" 
        android:id="@+id/updatedTextView"/> 
      </LinearLayout> 
     </LinearLayout> 
    </RelativeLayout> 
</ScrollView> 

对于文字,我已经试过强制行数为1,并具体设置高度,但似乎都没有奏效。另外,对于我已经尝试将代码转移到前端的循环,但它会弄乱布局。

任何人有任何改变建议?

+0

您可以通过给顶边距等于图像高度检查试试? –

+0

也删除textview的负边距 –

回答

1

您的布局是错误的。试试这个:

<RelativeLayout 
    android:id="@+id/container" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="135dp" 
     android:id="@+id/headerImageView" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentStart="true" android:layout_alignParentLeft="true" 
     android:scaleType="centerCrop" 
     android:adjustViewBounds="false" 
     android:background="@drawable/header_image_test" /> 

    <Button 
     android:layout_width="49dp" 
     android:layout_height="49dp" 
     android:layout_alignBottom="@id/headerImageView" 
     android:layout_alignRight="@id/headerImageView" 
     android:layout_marginRight="8dp" 
     android:layout_marginBottom="8dp" 
     android:background="@drawable/star"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/headerImageView" 
     android:orientation="horizontal" 
     android:layout_marginTop="-30dp" 
     android:id="@+id/main_details_layout"> 

     <TextView 
      android:id="@+id/waitTimeTextView" 
      android:layout_width="90dp" 
      android:layout_height="90dp" 
      android:text="@string/wait_time_default" 
      android:layout_marginLeft="8dp" 
      android:layout_marginRight="16dp" 
      android:gravity="center" 
      android:background="@drawable/color0" 
      android:textColor="#FFFFFF" 
      android:textSize="30dp" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="60dp" 
      android:layout_marginTop="30dp" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="0.7" 
       android:text="Attraction Name" 
       android:textSize="23dp" 
       android:layout_marginRight="8dp" 
       android:gravity="bottom" 
       android:lines="1" 
       android:id="@+id/attractionNameTextView"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="Last Updated" 
       android:textSize="16dp" 
       android:layout_marginRight="8dp" 
       android:gravity="bottom" 
       android:id="@+id/updatedTextView"/> 
     </LinearLayout> 
    </LinearLayout> 
</RelativeLayout> 

+0

为什么负边距。它已经在imageview下面对齐 –

+0

这样可以解决圆圈的问题,但是如果长度超过1行,文本仍然位于图像下方。有任何想法吗?我不知道为什么设置'行'到'maxLines'为1不起作用。 – user3746428

+0

@VivekMishra OP希望通过标题图像。 –