0

我有以下佈局:如何使圖像查看佈局的底部邊框?

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"  
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical" 
    android:clickable="true"  
    android:background="@drawable/mydrawable" 
    android:layout_width="match_parent"  
    android:layout_height=80dp"> 

    <TextView 
     android:id="@+id/my_text_view"   
     android:textSize="@dimen/label_text"  
     android:layout_width="fill_parent"  
     android:layout_height="match_parent"   
     android:paddingTop="@dimen/textPadding" 
     android:paddingLeft="@dimen/textPadding"  
     android:paddingRight="@dimen/textPadding"  
     android:text="This is some text"/> 

    <include layout="@layout/my_separator"/> 
</LinearLayout> 

和佈局my_separator.xml

<ImageView 
     xmlns:android="http://schemas.android.com/apk/res/android"  
     android:layout_width="match_parent"   
     android:layout_height="wrap_content"   
     android:layout_marginLeft="8dp"   
     android:layout_marginRight="8dp"  
     android:scaleType="fitXY"  
     android:src="#FF00FF"  /> 

基本上這個佈局具有文本視圖和充當分離器另一佈局。

問題:
我需要顯示在佈局和分離器中間的文本是在最底部。即充當父線性佈局的固體邊界。
所以現在是這樣的:

++++++++++++++++++++++++ (linear layout) 
This is some text 
--------------------- (Separator) 


++++++++++++++++++++++++ (linear layout) - bottom 

但我想

++++++++++++++++++++++++ (linear layout) 

This is some text 

------------------------ (Separator) - linear layout bottom 

我怎樣才能做到這一點?

注:我需要保持我已經爲佈局

+0

@SaschaKolberg:我試過在imageview裏面。它沒有工作 – Jim

回答

2

你不能這樣做,在一個LinearLayout背景。問題是LinearLayout中的元素是線性方式或排成一行,並且不能在一行中包含空格。它們只能以垂直或水平線性顯示。

您必須爲此使用RelativeLayout。這樣

<RelativeLayout> 
    <LinearLayout> 
    <!-- All your other elements in here --> 
    </LinearLayout> 
    <!-- Include you'r seperator here --> 
</RelativeLayout> 
+0

是的,使用'RelativeLayout'分隔符設置爲'layout_alignParentBottom =「true」',並且'LinearLayout'設置爲'layout_above =「@ + id/the_id_you_give_the_separator」' – kcoppock

+0

但是我不能以某種方式使圖像查看線性佈局的底部邊界? – Jim

0

東西其中包含的佈局有底部的佈局重心和根線狀佈局應該有比賽母公司的高度

+0

'layout_gravity =「bottom」'使它下面的文字,但不是邊界 – Jim

+0

,因爲根線性佈局有高度80 dp,使其匹配父 – borax12

+0

但我想線性佈局有至少80 dp高度 – Jim

0

正如大家所說的,你需要使用RelativeLayout的,但你需要包裝使用的LinearLayout佈局,唯一的問題是,如果你yave太多的文字,並有滾動的seprator是靜態的,但你可以嘗試檢查

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"  
    xmlns:tools="http://schemas.android.com/tools" 
    android:clickable="true"  
    android:background="@drawable/mydrawable" 
    android:layout_width="match_parent"  
    android:layout_height=80dp"> 

    <TextView 
     android:id="@+id/my_text_view"   
     android:textSize="@dimen/label_text"  
     android:layout_width="fill_parent"  
     android:layout_height="match_parent"   
     android:paddingTop="@dimen/textPadding" 
     android:paddingLeft="@dimen/textPadding"  
     android:paddingRight="@dimen/textPadding"  
     android:text="This is some text"/> 

    <LinearLayout 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:orientation="horizontal" 
     android:gravity="bottom|center"> 

      <include layout="@layout/my_separator"/> 
    </LinearLayout> 
</RelativeLayout> 
+0

但'android:gravity =「bottom」'一般適用於線性佈局 – Jim

+0

答案是錯誤的。 'android:gravity =「bottom」'確定孩子的佈局。第二個線性佈局本身不會走到底部 – Jim

0

TextViewinclude的只有c LinearLayout的孩子?如果是的話,你可以使用(我拿出那個不感興趣這種情況下屬性):

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

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:gravity="center_vertical" 
     android:text="This is some text"/> 

    <include 
     layout="@layout/separator" /> 
</LinearLayout> 

如果你覺得像TextView可能發生在需要比家長可以提供更多的空間,你可以設置一個maxHeight這將是(80 - heightOfTheSeparator - anyRelevantMargins/Paddings)