내 레이아웃은 Android Studio에서 생성 한 것 (작업 표시 줄이 비어 있음)을 기반으로합니다. 이것은 안드로이드 스튜디오를 생성 한 것처럼,XML 파일에서 여러 레이아웃을 다른 레이아웃에 추가
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_list, container, false);
return rootView;
}
Activity_stats이 변경되지 (I 단 하나 개의 자바 파일이) activity_stats.xml에 내 fragment_list.xml을 팽창하는 기본 코드입니다. fragment_list.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"
tools:context="com.company.dummyname.stats$PlaceholderFragment" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clipToPadding="false"
android:paddingTop="@dimen/network_margin_vertical"
android:paddingLeft="@dimen/network_margin_horizontal"
android:paddingRight="@dimen/network_margin_vertical" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/networkContainer"/>
</ScrollView>
</RelativeLayout>
networkContainer에 여러 자녀를 추가하고 싶습니다. 아이들은 다음과 같습니다 network.xml에서 레이아웃해야한다 :
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:grid="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.company.dummyname.stats$PlaceholderFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
grid:columnCount="2" >
<ImageView
android:layout_width="88dp"
android:layout_height="70dp"
android:background="#fff8cdac"
grid:layout_row="0"
grid:layout_column="0"
grid:layout_rowSpan="2"
android:src="@drawable/ic_launcher"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
grid:layout_row="0"
grid:layout_column="1"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9999.99"
android:id="@+id/totalToday"
android:textSize="32sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" today"
android:textSize="32sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="46dp"
android:paddingLeft="8dp"
grid:layout_row="1"
grid:layout_column="1"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9999.99"
android:id="@+id/totalYesterday"
android:textSize="24sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" yesterday"
android:textSize="24sp" />
</LinearLayout>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
grid:layout_row="2"
grid:layout_columnSpan="2">
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
style="@style/StatsCell" />
<TextView
style="@style/StatsCell"
android:text="Hits" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
style="@style/StatsCell"
android:text="Today"
android:layout_height="match_parent" />
<TextView
style="@style/StatsCell"
android:id="@+id/todayHits"
android:text="9999" />
</TableRow>
</TableLayout>
</android.support.v7.widget.GridLayout>
더 많은 데이터를 한 번 더 행이있을 것입니다,하지만 난 질문을 단순화하기 위해 그들을 제거. 목표는 다른 데이터로 network.xml의 많은 인스턴스를 갖는 것입니다. 어떻게 삽입하고 내부의 데이터를 변경합니까? 나는 Google에서 연구했지만 성공하지는 못했습니다. 하드 코드 된 문자열과 치수를 무시하십시오. 수정 해 드리겠습니다.
EDIT : network.xml 인스턴스의 수가 사용자 설정에 따라 달라 지므로 XML이 아닌 프로그래밍 방식으로 자식을 추가해야합니다. XML로
감사하지만 사용자 설정에 따라 네트워크 수가 다를 수 있으므로 프로그래밍 방식으로 레이아웃을 포함해야합니다. – Andrius
잘 자네가 XML을 보여줬고 코드에서 시도한 것이 아니라 내가 이것을 공유했다. 당신이 코드에서 처음 시도한 것을 질문에 추가하면 나는 당신을 안내 할 것입니다 –
나는 그것을 강조하기 위해 질문을 편집했습니다. Java 코드의 networkContainer 요소에 하나 이상의 network.xml 레이아웃을 포함해야합니다. 번호는 사용자 설정에 따라 다르므로 XML 포함을 사용할 수 없습니다. – Andrius