2014-12-22 2 views
0

이 내가 내가 첫 번째 행을 추천 행을 만들려는 말은, 코드의 내부를 복제 할 필요가 내 XML 코드안드로이드에서 상대 레이아웃을 복제하는 방법?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> 

<RelativeLayout 
    android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <Button android:id="@+id/search_text" 
     android:layout_alignParentRight="true" 
     android:text="Download" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
    <EditText android:id="@+id/search_box" 
     android:layout_alignParentLeft="true" 
     android:layout_toLeftOf="@id/search_text" 
     android:layout_centerVertical="true" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:hint="Paste Link Here" 
     android:inputType="text" 
     android:maxLines="1" /> 
</RelativeLayout> 

</RelativeLayout> 

이며, 나는 내 상대 레이아웃이 링크 및 다운로드 버튼을 표시해야 첫 번째 목록 아래의 4 시간

내 기본 페이지에서이 상대적인보기 5 개를 복제하고 표시하려면 어떻게해야합니까?

그냥 처음에 따라 본 대하여 도면을 복사하려는 단지 번째 미만 세번째 ...

+1

'ListView'사용에 대해 생각해 보셨나요? –

+1

'복제 예정'레이아웃을 별도의 XML로 이동 한 다음 태그를 사용하여 레이아웃을 포함시킵니다. 각 포함 된 레이아웃에 고유 한 ID를 할당 할 수 있습니다. –

+0

@XaverKapeller 아무도 아니요 –

답변

0

각 행

<RelativeLayout 
    android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <Button android:id="@+id/search_text" 
     android:layout_alignParentRight="true" 
     android:text="Download" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
    <EditText android:id="@+id/search_box" 
     android:layout_alignParentLeft="true" 
     android:layout_toLeftOf="@id/search_text" 
     android:layout_centerVertical="true" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:hint="Paste Link Here" 
     android:inputType="text" 
     android:maxLines="1" /> 
</RelativeLayout> 

를 나타 내기위한 새로운 row.xml 만들기 그리고, 안드로이드 레이아웃을 재사용에 대한 자세한 내용은 메인 레이아웃

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity" 
android:orientation="vertical"> 
    <include layout="@layout/row" id="@+id/row1" /> 
    <include layout="@layout/row" id="@+id/row2" /> 
    <include layout="@layout/row" id="@+id/row3" /> 
    <include layout="@layout/row" id="@+id/row4" /> 
</LinearLayout> 

에 복제하는 데 사용 여기 좀 Re-using layuts

공을 가지고 위의 댓글에서 언급 당신이이 방법을 수행하는 특별한 이유가없는 경우, 대신리스트 뷰를 사용한다 또는 GridLayout과 또는 귀하의 요구
+0

나는 공간과 그들을 넣어해야하지만, 그게 제대로 작동하지 않는, 그들은 각각의 하단에 서로를 넣어 bcuz other –

+0

컨테이너의 RelativeLayout를 수직 방향의 LinearLayout로 변경합니다. 위 내 수정 사항보기 –

관련 문제