我寻找的解决方案,但我无法正确理解,为什么发生。我试图把列表视图放在一个线性布局中,但它没有帮助。任何人都可以使用我的列表视图。为什么ListView中没有显示,虽然没有错误?
这里是我的XML - >
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_cards"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Card - 1"
android:textAlignment="center"
android:textColor="@color/crad_color"
android:textSize="34sp"
/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:orientation="vertical">
<ListView
android:id="@+id/list_num"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAlignment="center">
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_icon">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?actionBarItemBackground">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:text="Yes its there !" />
</FrameLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="?actionBarItemBackground"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:text="NO ! its not"
/>
</FrameLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
这里是我的Java代码 - >
package com.example.android.chooseanumber_magicalapp;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
import static android.R.attr.id;
import static android.R.id.list;
import static android.icu.lang.UCharacter.GraphemeClusterBreak.T;
import static com.example.android.chooseanumber_magicalapp.R.id.list_num;
/**
* Created by great on 25-05-2017.
*/
public class InstructionActivity extends AppCompatActivity{
ArrayList<String> list = new ArrayList<String>(30);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.instruction_activity);
list.add("1");
list.add("1");
list.add("1");
list.add("1");
list.add("1");
list.add("1");
list.add("1");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, list);
ListView lv = (ListView) findViewById(list_num);
{
lv.setAdapter(adapter);
}
}
}
编辑 - 从机器人工作室doesn't show anything in editor
截屏>
图像来自手机 - >
编辑__>
好球员,现在我得到如果我将改变风格
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
它显示列表项的问题!
之前它是
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
,但如果我想全屏幕(没有行动起来吧)?
身高列表视图父母是0dp在Lineary布局。使它有一些硬编码的宽度来测试你的输出。 – Shriram
有没有问题列表视图父母身高因为体重给出 –
刚试过。但同样的事情发生! –