获取数据以在Android应用程序中开发动态界面

时间:2015-10-23 14:39:08

标签: android imageview dynamic-ui

我正在开发一个Android应用程序,它现在是静态的。为了使其动态,我想从网络服务器或谷歌驱动器获取图像。我和我的照片很少。如何从网络服务器或谷歌硬盘获取图像?以下是我的代码 -

Bed.java

import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class Bed extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bed);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_bed, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == android.R.id.home) {
        this.finish();
        return true;
    } else {
        return super.onOptionsItemSelected(item);
    }

}
}

activity_bed.xml (目前,我已经提供了5个带有相应5个图像的ImageView,目前它是静态的。我想从网络服务器/谷歌驱动器中获取这5个图像。)

<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:orientation="vertical"
android:paddingLeft="10dp"
android:background="#00ffaa"
tools:context="com.example.rahulshaw.medizy.Bed">

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="vertical">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:layout_marginTop="5dp"
        android:paddingRight="10dp"
        android:layout_gravity="center_horizontal">


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hospital 1,Marathahalli"
    android:id="@+id/hosp1"
    android:gravity="center|bottom"
    android:textStyle="bold"
    android:textAppearance="?android:textAppearanceMedium"
    android:textColor="#ffffff"
    android:background="@drawable/picture1"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hospital 2,Domlur"
    android:id="@+id/hosp2"
    android:layout_marginTop="4dp"
    android:gravity="center|bottom"
    android:textStyle="bold"
    android:textAppearance="?android:textAppearanceMedium"
    android:textColor="#ffffff"
    android:background="@drawable/picture2"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hospital 3,Kundanahalli"
    android:id="@+id/hosp3"
    android:layout_marginTop="4dp"
    android:gravity="center|bottom"
    android:textStyle="bold"
    android:textAppearance="?android:textAppearanceMedium"
    android:textColor="#ffffff"
    android:background="@drawable/picture3"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hospital 4,Indiranagar"
    android:id="@+id/hosp4"
    android:layout_marginTop="4dp"
    android:gravity="center|bottom"
    android:textStyle="bold"
    android:textAppearance="?android:textAppearanceMedium"
    android:textColor="#ffffff"
    android:background="@drawable/picture1"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hospital 5,Koramangala"
    android:id="@+id/hosp5"
    android:layout_marginTop="4dp"
    android:gravity="center|bottom"
    android:textStyle="bold"
    android:textAppearance="?android:textAppearanceMedium"
    android:textColor="#ffffff"
    android:background="@drawable/picture5"/>

    </LinearLayout>
</ScrollView>
</LinearLayout>

请帮帮我......

1 个答案:

答案 0 :(得分:1)

Picasso是迄今为止最简单的获取图片的方式。它将为您处理线程http://square.github.io/picasso/