我试图使用RelativeLayout和layout_toRightOf,layout_below等来对齐视图,但我实现的最好是:
这是xml:
<?xml version="1.0" encoding="utf-8"?>
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<RelativeLayout
android:id="@+id/big"
android:layout_width="150dp"
android:layout_height="150dp"
android:background="@drawable/circular"
android:layout_margin="10dp"
android:layout_centerInParent="true"/>
<RelativeLayout
android:id="@+id/right"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/circular"
android:layout_toRightOf="@+id/big"
android:layout_centerVertical="true"/>
<RelativeLayout
android:id="@+id/left"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/circular"
android:layout_toLeftOf="@+id/big"
android:layout_centerVertical="true"/>
<RelativeLayout
android:id="@+id/top"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/circular"
android:layout_above="@+id/big"
android:layout_centerHorizontal="true"/>
<RelativeLayout
android:id="@+id/bottom"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/circular"
android:layout_below="@+id/big"
android:layout_centerHorizontal="true"/>
<RelativeLayout
android:id="@+id/northeast"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/circular"
android:layout_toRightOf="@+id/big"
android:layout_alignTop="@+id/top"/>
<RelativeLayout
android:id="@+id/northwest"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/circular"
android:layout_toLeftOf="@+id/big"
android:layout_alignTop="@+id/top"/>
<RelativeLayout
android:id="@+id/southeast"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/circular"
android:layout_toRightOf="@+id/big"
android:layout_below="@+id/big"/>
<RelativeLayout
android:id="@+id/southwest" …Run Code Online (Sandbox Code Playgroud) 我正在尝试从Android应用程序中的Instagram获取用户数据,因为我需要获取用户照片并在图库中显示,但我在获取用户数据时遇到问题.
这是代码:
private void fetchUserName() {
mProgress.setMessage("Finalizing ...");
new Thread() {
@Override
public void run() {
Log.i(TAG, "Fetching user info");
int what = WHAT_FINALIZE;
try {
URL url = new URL(API_URL + "/users/" + mSession.getId() + "/media/recent/?access_token=" + mAccessToken);
Log.d(TAG, "Opening URL " + url.toString());
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.connect();
String response = streamToString(urlConnection.getInputStream());
JSONObject jsonObj = (JSONObject) new JSONTokener(response).nextValue();
String name = jsonObj.getJSONObject("data").getString("full_name");
String bio = jsonObj.getJSONObject("data").getString("bio");
Log.i(TAG, "Got name: " + name + ", …Run Code Online (Sandbox Code Playgroud)