Intellij Android - белая область появляется внизу действия - PullRequest
0 голосов
/ 23 сентября 2018

В моей активности ListView в нижней части моей активности появляется большая белая область, и я не могу понять, почему и как это исправить. Почему я здесь, это список, который использует объекты в массиве списков.пользовательский адаптер и шаблон xml, заполненный данными объекта в просмотре списка.Надеюсь, что эта информация поможет, и любая помощь очень ценится, потому что я полностью потерян.

activity_product_list.xml (список действий)

<?xml version="1.0" encoding="utf-8"?>
<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:fitsSystemWindows="true"
        tools:context=".ProductList"
        android:orientation="vertical">

    <include layout="@layout/toolbarnormal"
             android:id="@+id/toolbar"/>

    <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <ListView
                android:id="@+id/lstProducts"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clipToPadding="true">



        </ListView>

    </ScrollView>

</LinearLayout>

ProductListLayout.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"
        android:layout_marginTop="10dp"
        android:background="@color/bodyLight">

    <RelativeLayout
            android:id="@+id/relProductContainer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/border"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_marginTop="10dp"
>

        <ImageView
                android:id="@+id/imgProductPic"
                android:layout_width="250dp"
                android:layout_height="250dp"
                android:layout_centerHorizontal="true"
                android:src="@drawable/placeholder"
                android:padding="5dp"
        />

        <TextView
                android:id="@+id/txtProductName"
                android:layout_width="240dp"
                android:layout_height="wrap_content"
                android:text="Product name"
                android:layout_below="@+id/imgProductPic"
                android:layout_centerHorizontal="true"
                android:textSize="24sp"
                android:maxLines="2"
                android:textAllCaps="false"
                android:textAlignment="center"
                android:layout_marginTop="5dp"
        />

        <TextView
                android:id="@+id/txtProductPrice"
                android:layout_width="240dp"
                android:layout_height="wrap_content"
                android:text="£49.99"
                android:layout_below="@+id/txtProductName"
                android:layout_centerHorizontal="true"
                android:textSize="15sp"
                android:layout_marginTop="5dp"
                android:maxLines="2"
                android:textAlignment="center"
                android:textAllCaps="false"
        />


        <EditText
                android:id="@+id/etProductAmount"
                android:layout_width="70dp"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:ems="10"
                android:layout_below="@+id/txtProductPrice"
                android:layout_toLeftOf="@+id/btnAddToBasket"
                android:layout_alignLeft="@+id/imgProductPic"
                android:layout_alignBottom="@id/btnAddToBasket"
                android:text="1"
                android:textAlignment="center"
        />

        <Button
                android:id="@+id/btnAddToBasket"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Add to basket"
                android:textAllCaps="true"
                android:textAlignment="center"
                android:textSize="14sp"
                android:layout_below="@+id/txtProductPrice"
                android:layout_alignRight="@+id/imgProductPic"
                android:layout_marginTop="10dp"
        />

    </RelativeLayout>

</RelativeLayout>

ProductList.java

package com.example.jack.cbdcalculator;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageButton;
import android.widget.ListView;

import java.util.ArrayList;

public class ProductList extends AppCompatActivity {

    private ImageButton imgbtnBack;
    private ListView lstProducts;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product_list);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        lstProducts = (ListView) findViewById(R.id.lstProducts);

        ArrayList<ProductObject> productObjectArrayList = new ArrayList<ProductObject>();

            ProductObject productObject = new ProductObject("Love Hemp™ 800mg 8% CBD Oil – 10ml", "A bottle contains 800MG of CBD Oil – 8% Purity in 10ml",
                "Certified Organic Hemp.\n" +
                        "Non-GMO, Vegan friendly, CO2 Extracted.\n" +
                        "Fast-Acting.\n" +
                        "Peppermint flavour available.\n" +
                        "Sourced from High-CBD Hemp cultivated in the US.\n" +
                        "Strict GMP Manufacturing & Quality Control process.\n" +
                        "Public Third-Party Lab Test Results.",
                    "https://i1.wp.com/benefitcbduk.co.uk/wp-content/uploads/2018/02/what-are-the-benefits-of-cbd.jpg?fit=1200%2C1200&ssl=1", 49.99);

        ProductObject productObject2 = new ProductObject("Koi CBD – Multi-Purpose CBD Vape or Tincture Oil (250MG-1000MG)",
                "A novel Cannabidiol product from Koi CBD, the Multi-Purpose CBD Vape E-liquid or Tincture CBD Oil. Can’t decide whether to buy Vape or CBD Oil? Why not do both?",
                " No Flavoured Additives.\n" +
                        "> Non-Psychoactive (Zero THC).\n" +
                        "> Hexane Free.\n" +
                        "> GMO Free.\n" +
                        "> Pesticide Free.\n" +
                        "> Multi-Purpose – Perfect vape juice to add to other e-liquids and ideal for use as a tincture or to add to other foods/drinks.",
                "https://i2.wp.com/benefitcbduk.co.uk/wp-content/uploads/2018/06/koi-cbd-250-gold.png?fit=1080%2C1080&ssl=1", 44.99);

            productObjectArrayList.add(productObject);
            productObjectArrayList.add(productObject2);

            ProductAdapter productAdapter = new ProductAdapter(this, R.layout.productlistlayout, productObjectArrayList);
            lstProducts.setAdapter(productAdapter);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main_menu, menu);
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        switch(item.getItemId()) {
            case R.id.basket:
                startActivity(new Intent(this, Basket.class));
            default:
                return super.onOptionsItemSelected(item);
        }
    }

}

ProductObject.java

package com.example.jack.cbdcalculator;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageButton;
import android.widget.ListView;

import java.util.ArrayList;

public class ProductList extends AppCompatActivity {

    private ImageButton imgbtnBack;
    private ListView lstProducts;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product_list);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        lstProducts = (ListView) findViewById(R.id.lstProducts);

        ArrayList<ProductObject> productObjectArrayList = new ArrayList<ProductObject>();

            ProductObject productObject = new ProductObject("Love Hemp™ 800mg 8% CBD Oil – 10ml", "A bottle contains 800MG of CBD Oil – 8% Purity in 10ml",
                "Certified Organic Hemp.\n" +
                        "Non-GMO, Vegan friendly, CO2 Extracted.\n" +
                        "Fast-Acting.\n" +
                        "Peppermint flavour available.\n" +
                        "Sourced from High-CBD Hemp cultivated in the US.\n" +
                        "Strict GMP Manufacturing & Quality Control process.\n" +
                        "Public Third-Party Lab Test Results.",
                    "https://i1.wp.com/benefitcbduk.co.uk/wp-content/uploads/2018/02/what-are-the-benefits-of-cbd.jpg?fit=1200%2C1200&ssl=1", 49.99);

        ProductObject productObject2 = new ProductObject("Koi CBD – Multi-Purpose CBD Vape or Tincture Oil (250MG-1000MG)",
                "A novel Cannabidiol product from Koi CBD, the Multi-Purpose CBD Vape E-liquid or Tincture CBD Oil. Can’t decide whether to buy Vape or CBD Oil? Why not do both?",
                " No Flavoured Additives.\n" +
                        "> Non-Psychoactive (Zero THC).\n" +
                        "> Hexane Free.\n" +
                        "> GMO Free.\n" +
                        "> Pesticide Free.\n" +
                        "> Multi-Purpose – Perfect vape juice to add to other e-liquids and ideal for use as a tincture or to add to other foods/drinks.",
                "https://i2.wp.com/benefitcbduk.co.uk/wp-content/uploads/2018/06/koi-cbd-250-gold.png?fit=1080%2C1080&ssl=1", 44.99);

            productObjectArrayList.add(productObject);
            productObjectArrayList.add(productObject2);

            ProductAdapter productAdapter = new ProductAdapter(this, R.layout.productlistlayout, productObjectArrayList);
            lstProducts.setAdapter(productAdapter);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main_menu, menu);
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        switch(item.getItemId()) {
            case R.id.basket:
                startActivity(new Intent(this, Basket.class));
            default:
                return super.onOptionsItemSelected(item);
        }
    }

}

ProductAdapter.java

package com.example.jack.cbdcalculator;

public class ProductObject {

    String productName, productDescription, productExtraInfo, productImageUrl;
    Double productPrice;

    public ProductObject(String productName, String productDescription, String productExtraInfo, String productImageUrl, Double productPrice) {
        this.productName = productName;
        this.productDescription = productDescription;
        this.productExtraInfo = productExtraInfo;
        this.productImageUrl = productImageUrl;
        this.productPrice = productPrice;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public String getProductDescription() {
        return productDescription;
    }

    public void setProductDescription(String productDescription) {
        this.productDescription = productDescription;
    }

    public String getProductExtraInfo() {
        return productExtraInfo;
    }

    public void setProductExtraInfo(String productExtraInfo) {
        this.productExtraInfo = productExtraInfo;
    }

    public String getProductImageUrl() {
        return productImageUrl;
    }

    public void setProductImageUrl(String productImageUrl) {
        this.productImageUrl = productImageUrl;
    }

    public Double getProductPrice() {
        return productPrice;
    }

    public void setProductPrice(Double productPrice) {
        this.productPrice = productPrice;
    }
}

1 Ответ

0 голосов
/ 24 сентября 2018

В вашем ProductListLayout.xml, первом объявлении android:layout_height="match_parent", вместо того, чтобы атрибут соответствовал родительскому, он должен иметь константу или любой другой размер, который не занимает начальную часть экрана.Прямо сейчас вы видите этот пробел, потому что отображается только первый элемент, так как нет места для других.Попробуйте изменить его на 200dp.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...