Android UI看起来不太好

Android UI看起来不太好,android,user-interface,Android,User Interface,我是Android的初学者。我的小应用程序运行良好,但它的UI看起来很难看。你能帮我做得更好吗?例如:它的图像看起来太大了,我们可以把它缩小一点吗 下面是代码片段 MainActivity.java package com.example.hacback17.listviewwithimagesadvanced; import android.content.Context; import android.content.res.Resources; import android.suppor

我是Android的初学者。我的小应用程序运行良好,但它的UI看起来很难看。你能帮我做得更好吗?例如:它的图像看起来太大了,我们可以把它缩小一点吗

下面是代码片段

MainActivity.java

package com.example.hacback17.listviewwithimagesadvanced;

import android.content.Context;
import android.content.res.Resources;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    ListView list;
    String[] memeTitle;
    String[] memeDescription;
    // getting ids of images from drawable
    int[] images = {R.drawable.number_one,R.drawable.number_two, R.drawable.number_three, R.drawable.number_four, R.drawable.number_five,
            R.drawable.number_six, R.drawable.number_seven, R.drawable.number_eight, R.drawable.number_nine, R.drawable.number_ten};

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



        Resources resources = getResources();
        memeTitle = resources.getStringArray(R.array.titles);
        memeDescription = resources.getStringArray(R.array.titles);

        // Getting the reference of the ListView
        list = (ListView) findViewById(R.id.listView);

        MyAdapter adapter = new MyAdapter(this, memeTitle, images, memeDescription );
        list.setAdapter(adapter);
    }
}

// Custom ArrayAdapter
class MyAdapter extends ArrayAdapter<String>
{
    Context context;
    int[] images; // getting the reference of images.
    String[] titleArray; // getting the reference of titles array
    String[] descriptionArray; // getting the reference of description array

    public MyAdapter(Context context, String[] titles, int[] img, String[] description) {
        super(context, R.layout.single_row, R.id.textView, titles);
        this.context = context;
        this.images = img;
        this.titleArray = titles;
        this.descriptionArray = description;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        // Let's get the reference of LayoutInflater to get the XML into Java code.
        LayoutInflater  inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View row = inflater.inflate(R.layout.single_row, parent, false);

        ImageView myImage = (ImageView) row.findViewById(R.id.imageView);
        TextView myTitle = (TextView) row.findViewById(R.id.textView);
        TextView myDescription = (TextView) row.findViewById(R.id.textView2);


        myImage.setImageResource(images[position]);

        myTitle.setText(titleArray[position]);

        myDescription.setText(descriptionArray[position]);



        return row; 
    }
}
activity_main.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="com.example.hacback17.listviewwithimagesadvanced.MainActivity">


    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/listView"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>
single_row.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:src="@drawable/number_one"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:layout_margin="10dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/textView"
        android:layout_alignTop="@+id/imageView"
        android:layout_alignParentEnd="true"
        android:layout_toEndOf="@+id/imageView" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Small Text"
        android:id="@+id/textView2"
        android:layout_alignEnd="@+id/textView"
        android:layout_alignStart="@+id/textView"
        android:layout_below="@+id/textView" />

</RelativeLayout>

UI如下所示:

将图像布局宽度和高度包装为30dp

 <ImageView
        android:src="@drawable/number_one"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:id="@+id/imageView"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:layout_margin="10dp" />
在阵列适配器中,使用以下功能:

myImage.setMaxWidth(MAX_WIDTH);
myImage.setMaxHeight(MAX_HEIGHT);

在“最大宽度”和“最大高度”中使用您自己的值。

您需要具体说明您需要什么。“好的”和“更好的”并不具体。这不是一个编程问题…@ThomasW我想让它变得好起来。@BABLUKUMAR Nice是一个足够具体的人物描述,谢谢你的帮助。这是一个简单的问题,但我不知道我以前想不起来。是的。。还要注意saini的回答。。如果您想使用java类设置高度和宽度,这也是一个很好的答案。嗨,Sagar,我不知道为什么网站阻止我提问,可能是我问了一些低质量的问题。但在我看来,问题可能是小问题,也可能是大问题。你能帮我编码吗?因为你似乎对安卓有很好的了解?我还从你的个人资料中注意到,你喜欢与他人分享你的知识。期待尽快收到您的来信。谢谢您的电子邮件id。我会将代码片段发送给您。我还想知道你是否总是活跃在这个网站上。因为我很快就收到了你的回复。。我很乐意帮助开发者