mardi 26 mai 2015

How can I divide a screen in 2 equal parts : one with an image and the other with textviews?

I'm making an Android news app and when I or the user would access a list of news, each news would take the whole screen and would be divided in two parts (50/50) : first part would be the image and the other half would be the textviews (for the title, date and article). A couple of apps are using the same trick.

I've tried many options but I cannot manage to make them fit into my screen and get what I'm looking for.

As you will see I've added the layout_weight parameter but it does not make any difference at all.

Any idea anyone ??

Here's my xml file :

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:weightSum="1" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/news_hockey2"
        android:adjustViewBounds="true" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="title"
        android:id="@+id/title"
        android:layout_marginTop="5dp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="date_of_pub"
        android:id="@+id/date_of_pub"
        android:layout_marginTop="5dp"
        android:layout_weight="0.1" />


    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="link"
        android:id="@+id/link"
        android:layout_marginBottom="25dp"
        android:layout_marginTop="5dp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="article"
        android:id="@+id/article"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="15dp" />

</LinearLayout>

Aucun commentaire:

Enregistrer un commentaire