以编程方式保存imageViews

时间:2017-03-22 08:10:23

标签: android imageview save android-linearlayout

我有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);

1 个答案:

答案 0 :(得分:0)

添加你的xlm

<ImageView
            android:id="@+id/iv_houseForChickens  "
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/R.drawable.house"/>

代码

ImageView houseForChickens  = (ImageView ) findViewById(R.id.iv_houseForChickens  );

看看你是想在代码中设置src还是放入xlm,直到你