android列表布局无法实现
我想在报价文本的列表视图中实现以下布局 我正在尝试橙色背景而不是灰色,绿色文本背景而不是白色: 以下是xmlandroid列表布局无法实现,android,textview,Android,Textview,我想在报价文本的列表视图中实现以下布局 我正在尝试橙色背景而不是灰色,绿色文本背景而不是白色: 以下是xml <?xml version="1.0" encoding="utf-8"?> <GridView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridview" android:layout_width="fill_parent" andr
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="1"
android:stretchMode="columnWidth"
android:gravity="center"
/>
the file quote_text.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_orange_dark" >
<TextView
android:id="@+id/quotetext1"
android:background="@android:color/holo_green_light"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:paddingLeft="20dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:paddingRight="20dp"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:textSize="15dp" >
</TextView>
</LinearLayout>
根据dieter_h的回答,我还尝试使用以下内容
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<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="wrap_content"
android:orientation="vertical"
android:background="@android:color/holo_orange_dark">
<TextView
android:id="@+id/quotetext1"
android:background="@android:color/holo_green_light"
android:layout_width="match_parent"
android:layout_height="100dp"
tools:text="kfjjkdshf jkhs jkdhs sdjh jksdh s sdjhfjksdh kjsdfh"
android:padding="20dp"
android:layout_margin="15dp"
android:textSize="15dp" />
</LinearLayout>
但它仍会根据需要显示尝试更改quote_text.xml:
将GridView更改为ListView:
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
将XML布局更改为以下内容: 列表视图
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:background="@android:color/holo_orange_dark">
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="16dp"
android:divider="@android:color/transparent"/>
</FrameLayout>
项目视图
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:background="@android:color/holo_green_dark"
android:textSize="14sp"/>
这就是你应该得到的:
它再次展示了同样的东西。带有文本的整个绿色。是否与视图gimkan=inflater.inflater.layout.quote_text、parent、false有关;我尝试查看gimkan=inflater.inflater.layout.quote\u text,null。没有变化。它是完全相同的绿色,文本布局没有变化。它显示与文本相同的绿色屏幕。它不显示您提到的tools.text文本。如果我在androidstudio中检查这个xml,它将显示来自settext的文本。它在橙色背景上显示预期的绿色文本框。但当我编译并运行它时,它不会用你的输入编辑我的问题。它仍然没有显示出我想要的,你明白了。为什么我们要用。在很多地方我都搜索过它没有提到的地方。你可能首先想在ListView中使用边距,但根据我的经验,如果有边距的视图没有父视图,Android不会考虑边距,因此你可以使用FrameLayout或任何视图组继承的类LinearLayout包装ListView,RelativeLayout…,但是FrameLayout毕竟是最轻的,所以我选择FrameLayout,然后为它设置填充,或者不为FrameLayout设置填充,而是为ListView设置边距。希望你得到它;
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:background="@android:color/holo_orange_dark">
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="16dp"
android:divider="@android:color/transparent"/>
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:background="@android:color/holo_green_dark"
android:textSize="14sp"/>