2013-02-20 44 views
0

我想将当前布局中的视图元素与通过Android中的标记包含的视图元素对齐。如何对齐Android中包含的布局中的视图元素

布局1:(Layout1.xml)

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 

    <ImageView 
     android:id="@+id/click_icon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/desc" 
     android:padding="4dp" 
     android:src="@drawable/icon_click" /> 

    <RelativeLayout 
        android:id="@+id/relativeLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:gravity="bottom" 
      android:paddingLeft="8dp" 
      android:paddingTop="6dp" 
      android:text="@string/textview1" 
     /> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/textView1" 
      android:text="@string/textView2" 
     /> 
    </RelativeLayout> 

</LinearLayout> 

布局2:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <include 
     android:id="@+id/includedLayout" 
     layout="@layout/Layout1" /> 

    <View 
     android:id="@+id/seperator" 
     android:layout_width="wrap_content" 
     android:layout_height="1dp" 
     android:alpha="0.3" 
     android:background="#FFFFFF" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
     <!-- I want to align this layout with relative layout present in the 
     Layout1.xml file which is included above --> 

    </LinearLayout> 

</LinearLayout> 

我要对齐与RelativeLayout的所述Layout2.xml第二的LinearLayout在Layout1.xml文件,该文件是包含在Layout2.xml文件中。

如果有人知道解决方案,请让我知道。

谢谢。

+0

你要对齐文本观点,即线性布局?你能否更清楚 – akaya 2013-02-20 12:29:02

+0

想要将Layout2.xml文件中的第二个LinearLayout与Layout1.xml文件中的RelativeLayout对齐[上面的代码只是一个示例,此RelativeLayout可以包含除文本视图以外的更多视图]。 – Suman 2013-02-21 10:34:28

回答

0

你不尝试把你想要对齐的布局部分放到另一个文件中,只将该文件包含到你的layout2.xml中,并在layout2.xml中手动编码提醒部分。 我的意思是采取 `

<TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:gravity="bottom" 
     android:paddingLeft="8dp" 
     android:paddingTop="6dp" 
     android:text="@string/textview1" 
    /> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/textView1" 
     android:text="@string/textView2" 
    /> 
</RelativeLayout>` 

这部分在另一个单独的文件和手动添加的ImageView中layout2.xml

+0

谢谢,但重用的目的消失:),我想重用包括图像视图。 – Suman 2013-02-21 10:35:30