-1
我有3個水平線性佈局,我在其中以編程方式添加圖像查看。當我關閉應用程序並重新打開它時,它不會保存我添加的圖像視圖。我該如何保存這些圖像並將其重新加載到簡歷上?以編程方式保存圖像查看
XML:
<TextView
android:id="@+id/textView8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Chickens"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="HardcodedText" />
<LinearLayout
android:id="@+id/Chickens"
android:layout_width="match_parent"
android:layout_height="65dp"
android:orientation="horizontal">
</LinearLayout>
<TextView
android:id="@+id/textView9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Cows"
android:textColor="#000000"
android:textSize="24dp"
tools:ignore="HardcodedText,SpUsage" />
<LinearLayout
android:id="@+id/Cows"
android:layout_width="match_parent"
android:layout_height="65dp"
android:orientation="horizontal">
</LinearLayout>
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Horses"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="HardcodedText" />
<LinearLayout
android:id="@+id/Horses"
android:layout_width="match_parent"
android:layout_height="65dp"
android:orientation="horizontal">
</LinearLayout>
在活動時間:
Chickens = (LinearLayout) findViewById(R.id.Chickens);
Cows = (LinearLayout) findViewById(R.id.Cows);
Horses = (LinearLayout) findViewById(R.id.Horses);
ImageView houseForChickens = new ImageView(this);
houseForChickens.setImageResource(R.drawable.house);
Chickens.addView(houseForChickens, 300, 300);
保存imageview?你的意思是src?你是如何從webservice獲得圖像的?或本地。如果來自webservice,則可以將鏈接保存在數據庫或共享首選項中。如果你從drawerable(本地)獲得它,你不需要保存,你可以重新加載它。 – kggoh
imageview是從drawable添加的:ImageView houseForChickens = new ImageView(this); houseForChickens.setImageResource(R.drawable.house);)然後我將它添加到佈局中(Chickens.addView(houseForChickens,300,300);),我該如何重新加載它?我是一個初學者.. – Anr14
因爲你說你關閉了應用程序並重新打開它。所以應用程序重新啓動,它將再次運行imageView的加載。如果你的應用使用片段。片段加載時,它也會加載圖像。也許你向我展示你的圖像所在的.xml文件。以及你如何調用這個XML。 – kggoh