2017-05-03 10 views
0

내 응용 프로그램에서는 두 가지 다른 활동에서 RecyclerView을 사용해야합니다. 기본 레이아웃 (리사이클 러 뷰)이 두 액티비티에서 동일하기 때문에 레이아웃을 확장하려고 생각했지만 가능한지 모릅니다. 와 나는 이런 식으로 뭔가 의미 "레이아웃을 확장하는":이 경우레이아웃을 확장 할 수 있습니까?

을 내 base_layout.xml :

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:tools="http://schemas.android.com/tools""> 

    <android.support.v7.widget.RecyclerView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/recyclerView"> 
    </android.support.v7.widget.RecyclerView> 
</RelativeLayout> 

child_layout.xml에서 같은 것을 할 싶습니다 :

include "base_layout.xml" 
<Button 
      android:id="@+id/btnAddVehicle" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="+" 
      android:onClick="launchAddVehicleActivity"/> 

따라서 chid_layout.xml을 사용하는 활동은 RecyclerViewButton을 내부에 가지고있을 것입니다.

이렇게 할 수 있습니까? 당신이 사용자 정의 구성 요소를 작성해야 레이아웃 내부에 버튼을 추가하려면

답변

1

당신은 일반적인 레이아웃을 만들 수를 팽창 RelativeLayout의 상속 클래스를 만들 수 안드로이드 문서를 참조하십시오.

일반 레이아웃 my_generic_layout.xml

<RelativeLayout 
android:id="@+id/generic_layout"> 
    <RecyclerView/> 
</RelativeLayout> 

레이아웃의 활동

<RelativeLayout 
android:id="@+id/layout_1"> 
<include layout="@layout/my_generic_layout" /> 
</RelativeLayout> 


<RelativeLayout 
android:id="@+id/layout_2"> 
<include layout="@layout/my_generic_layout" /> 
</RelativeLayout> 
+0

잘 될 것이라고 생각 정확히 내가 뭘 원하는지, 대단히 감사합니다 :) – Clyky

0

는이 <include layout="@layouts/chid_layout" />

관련 문제