新闻提要的Android桌面布局设计

新闻提要的Android桌面布局设计,android,android-layout,tablelayout,android-tablelayout,Android,Android Layout,Tablelayout,Android Tablelayout,我目前正在我的Android应用程序中开发一个类似于新闻提要的活动。我对Android开发非常陌生 显示了我试图实现的一个示例。 总而言之: 新闻单 对于每条新闻,左栏显示的图片大小与每条新闻的图片大小相同,右栏显示的右气泡显示链接文章的日期、标题和第一行 后端通信很容易设置,我在一个单独的线程上收到一个新闻列表,并使用UI线程更新视图。 不幸的是,视图格式对我来说并不容易。 我尝试了几种混合表格布局和相对布局的解决方案。 不幸的是,这些解决方案没有一个是有效的 在这个阶段,我遇到了比屏幕宽度大

我目前正在我的Android应用程序中开发一个类似于新闻提要的活动。我对Android开发非常陌生

显示了我试图实现的一个示例。 总而言之:

新闻单

对于每条新闻,左栏显示的图片大小与每条新闻的图片大小相同,右栏显示的右气泡显示链接文章的日期、标题和第一行

后端通信很容易设置,我在一个单独的线程上收到一个新闻列表,并使用UI线程更新视图。 不幸的是,视图格式对我来说并不容易。 我尝试了几种混合表格布局和相对布局的解决方案。 不幸的是,这些解决方案没有一个是有效的

在这个阶段,我遇到了比屏幕宽度大的行

为了构建布局,我使用2个XMLs&使用代码更新文本值和图片

第一个XML包含TableLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1"
    android:layout_marginTop="30dp"
    android:layout_marginBottom="30dp"
    android:id="@+id/tblFeed">

</TableLayout>
第二个XML包含表行模式:

<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="1"
    android:id="@+id/tblRow">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"  android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    android:paddingBottom="0dp">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:padding="3dip"
        android:gravity="center"
        android:id="@+id/imgPin"
        android:src="@drawable/android_icon"/>
</RelativeLayout>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    android:paddingBottom="0dp">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    android:layout_marginLeft="30dp"
    android:padding="3dip"
    android:textColor="#000000"
    android:textSize="18sp"
        android:gravity="right"
    android:id="@+id/txtDate"/>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    android:layout_marginLeft="30dp"
    android:padding="3dip"
    android:textColor="#000000"
    android:textSize="18sp"
    android:id="@+id/txtType"
    android:layout_below="@+id/txtDate"/>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    android:layout_marginLeft="30dp"
    android:padding="3dip"
    android:textColor="#000000"
    android:textSize="18sp"
    android:id="@+id/txtTitle"
    android:layout_below="@+id/txtType"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    android:layout_marginLeft="30dp"
    android:padding="3dip"
    android:textColor="#000000"
    android:textSize="18sp"
    android:id="@+id/txtDescription"
    android:layout_below="@+id/txtTitle"/>
</RelativeLayout>
我遇到了几个问题:

图片未在行中居中 第二列中的文本视图大于屏幕 我还想知道混合使用TableLayouts和RelativeLayouts是否真的是实现这一点的最佳方法


你能告诉我吗?

你不应该使用表格布局。相反,通常使用相对长度。对于包含新闻1和新闻2的卡片,请使用

我认为您不需要表格布局。这是一个由列和行组成的网格。我认为您最好使用ListView。它只会在屏幕上为您提供一个信息行列表,您可以使用自己的图像、文本等布局进行自定义。@drschultz我按照您的建议使用ListView而不是TableLayout,然后。。。一切都很好很高兴听到这个消息!您还需要熟悉RecyclerView,它本质上是ListView的一个更灵活的版本。