如何让RelativeLayout出现在LinearLayout旁边?

时间:2013-03-21 15:13:37

标签: android android-layout android-linearlayout android-relativelayout

我正在努力实现以下目标:

enter image description here

我正在尝试显示LinearLayout旁边的RelativLayout

我已经尝试将RelativeLayout打包成LinearLayout,但这没有任何区别。 我正在使用RelativeLayout在图片缩略图前面显示文字。

但是,我仍然无法理解,我尝试了一切。

这里是XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"      
    android:gravity="left|center"
    android:layout_weight="1"  
    android:orientation="vertical"
    android:background="#313131" >     
    <LinearLayout
        android:layout_width="fill_parent"              
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="left" >       
        <ImageView
            android:id="@+id/otv2"         
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"         
            android:layout_marginRight="10dp"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"          
            android:src="@drawable/otv_2"          
            android:gravity="left" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"         
            android:layout_marginRight="10dp"
            android:layout_marginTop="5dp"  
            android:layout_weight="1"       
            android:text="sehen was bewegt" 
            android:textColor="#FFFFFF"       
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:gravity="right" />
    </LinearLayout>    
    <View android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="#007cc2"/> 
    <LinearLayout      
        android:layout_width="fill_parent"             
        android:layout_height="wrap_content"
        android:layout_marginBottom="25dip"
        android:orientation="vertical"  
        android:adjustViewBounds="true"  
        android:gravity="left|top" >     
        <RelativeLayout             
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"                 
            android:layout_gravity="left" >           
            <ImageView
                android:id="@+id/otv2_thumb"    
                android:adjustViewBounds="true"       
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"         
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"                
                android:layout_marginBottom="3dp" />

            <TextView android:id="@+id/duration"
                android:layout_width="fill_parent"  
                android:layout_height="wrap_content" 
                android:textColor="#ffffff" 
                android:layout_alignLeft="@+id/otv2_thumb"
                android:layout_alignTop="@+id/otv2_thumb"
                android:layout_alignRight="@+id/otv2_thumb"
                android:layout_alignBottom="@+id/otv2_thumb"    
                android:layout_marginLeft="10dp"        
                android:text="00:45"
                android:textStyle="bold"
                android:gravity="left|bottom"                          
                android:textAppearance="?android:attr/textAppearanceMedium" />      
        </RelativeLayout>      
        <LinearLayout       
            android:orientation="vertical"
            android:layout_width="wrap_content"        
            android:layout_height="wrap_content"
            android:layout_weight="1"                 
            android:layout_marginTop="10dp"              
            android:background="#666666"
            android:gravity="right|top">       
            <TextView android:id="@+id/location"
                android:layout_width="fill_parent"   
                android:textColor="#3E3F41" 
                android:paddingLeft="0dp"                    
                android:layout_height="fill_parent"
                android:text="EICHENZELL - 03.03.1303"     
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:gravity="left|top"/>            
            <TextView 
                android:id="@+id/text"       
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="0dp"                     
                android:textColor="#FFFFFF"
                android:text="asdaf asgsadg gadg "     
                android:textAppearance="?android:attr/textAppearanceSmall" 
                android:gravity="left|center" />    
        </LinearLayout>
    </LinearLayout>   
</LinearLayout>

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

尝试将android:orientation="vertical"更改为相对和线性布局的父LinearLayout的水平。 像这样:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"      
    android:gravity="left|center"
    android:layout_weight="1"  
    android:orientation="vertical"
    android:background="#313131" >     
    <LinearLayout
        android:layout_width="fill_parent"              
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="left" >       
        <ImageView
            android:id="@+id/otv2"         
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"         
            android:layout_marginRight="10dp"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"          
            android:src="@drawable/otv_2"          
            android:gravity="left" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"         
            android:layout_marginRight="10dp"
            android:layout_marginTop="5dp"  
            android:layout_weight="1"       
            android:text="sehen was bewegt" 
            android:textColor="#FFFFFF"       
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:gravity="right" />
    </LinearLayout>    
    <View android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="#007cc2"/> 
    <LinearLayout      
        android:layout_width="fill_parent"             
        android:layout_height="wrap_content"
        android:layout_marginBottom="25dip"
        android:orientation="horizontal"  
        android:adjustViewBounds="true"  
        android:gravity="left|top" >     
        <RelativeLayout             
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"                 
            android:layout_gravity="left" >           
            <ImageView
                android:id="@+id/otv2_thumb"    
                android:adjustViewBounds="true"       
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"         
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"                
                android:layout_marginBottom="3dp" />

            <TextView android:id="@+id/duration"
                android:layout_width="fill_parent"  
                android:layout_height="wrap_content" 
                android:textColor="#ffffff" 
                android:layout_alignLeft="@+id/otv2_thumb"
                android:layout_alignTop="@+id/otv2_thumb"
                android:layout_alignRight="@+id/otv2_thumb"
                android:layout_alignBottom="@+id/otv2_thumb"    
                android:layout_marginLeft="10dp"        
                android:text="00:45"
                android:textStyle="bold"
                android:gravity="left|bottom"                          
                android:textAppearance="?android:attr/textAppearanceMedium" />      
        </RelativeLayout>      
        <LinearLayout       
            android:orientation="vertical"
            android:layout_width="wrap_content"        
            android:layout_height="wrap_content"
            android:layout_weight="1"                 
            android:layout_marginTop="10dp"              
            android:background="#666666"
            android:gravity="right|top">       
            <TextView android:id="@+id/location"
                android:layout_width="fill_parent"   
                android:textColor="#3E3F41" 
                android:paddingLeft="0dp"                    
                android:layout_height="fill_parent"
                android:text="EICHENZELL - 03.03.1303"     
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:gravity="left|top"/>            
            <TextView 
                android:id="@+id/text"       
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="0dp"                     
                android:textColor="#FFFFFF"
                android:text="asdaf asgsadg gadg "     
                android:textAppearance="?android:attr/textAppearanceSmall" 
                android:gravity="left|center" />    
        </LinearLayout>
    </LinearLayout>   
</LinearLayout>