TheDevMan
TheDevMan

Reputation: 5954

Dialog activity - text gets cut in android

I am trying a simple contacts app that displays all the phones etc. When I click on the contact name, it displays the contact numbers in a dialogue activity. I can see the name and numbers properly when I have less numbers.. But if I have more numbers the name part in the activity gets cut.. Please check the below screen shot.

Can you see that Joe David text and profile picture gets cut. The numbers are displayed properly as it is in listview hence I can scroll down or up to view all the numbers.

How to fix this? - This screen shot is from Nexus 5 but same on Nexus 4 / Galaxy nexus too.. I have tried it on these.. Not sure on other phones..

XML Details:

<?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:orientation="vertical" >

<LinearLayout
    android:id="@+id/LayoutContactNumber"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".20"
    android:background="@drawable/blackbg"
    android:gravity="left|center"
    android:orientation="horizontal" >

    <com.res.dese.number.ResizableImageView
        android:id="@+id/CImage"
        android:layout_width="120px"
        android:layout_height="120px"
        android:padding="5dp"
        android:scaleType="fitXY"
        android:src="@drawable/no_pic" />

    <TextView
        android:id="@+id/PhoneLabel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:freezesText="true"
        android:gravity="center|left"
        android:marqueeRepeatLimit="marquee_forever"
        android:paddingLeft="5dp"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:text="XXX"
        android:textColor="#2CABE2"
        android:textSize="30sp"
        android:textStyle="bold" />
</LinearLayout>

<ImageView
    android:id="@+id/whiteline"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:src="@drawable/whiteline" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".65"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="#007FFF"
        android:dividerHeight="3dp" >
    </ListView>
</LinearLayout>

<ImageView
    android:id="@+id/whiteline"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:src="@drawable/whiteline" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".15"
    android:gravity="center"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/okandeditlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <LinearLayout
            android:id="@+id/editContactlinearlayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight=".50"
            android:orientation="horizontal"
            android:paddingRight="2dp" >

            <ImageView
                android:id="@+id/editnumber"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/newedit" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayoutDeleteConatct"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight=".50"
            android:orientation="horizontal"
            android:paddingLeft="2dp" >

            <ImageView
                android:id="@+id/del"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/newdelete" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

Screen shot of issue

Thanks!

Upvotes: 3

Views: 2420

Answers (8)

Kaushik
Kaushik

Reputation: 6162

Give a try with this layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2" >

        <com.res.dese.number.ResizableImageView
            android:id="@+id/CImage"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:padding="5dp"
            android:scaleType="fitXY"
            android:src="@drawable/no_pic" />

        <TextView
            android:id="@+id/PhoneLabel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:freezesText="true"
            android:gravity="center|left"
            android:marqueeRepeatLimit="marquee_forever"
            android:layout_marginLeft="5dp"
            android:scrollHorizontally="true"
            android:singleLine="true"
            android:text="XXX"
            android:textColor="#2CABE2"
            android:textSize="30sp"
            android:textStyle="bold" />
    </LinearLayout>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/whiteline" />

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="12" >
    </ListView>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/whiteline" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:padding="5dp" >

        <ImageView
            android:id="@+id/editnumber"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:src="@drawable/newedit" />

        <ImageView
            android:id="@+id/del"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_weight="1"
            android:src="@drawable/newdelete" />
    </LinearLayout>

</LinearLayout>

Instead of LinearLayout you can use RelativeLayout

Upvotes: 6

Rick Royd Aban
Rick Royd Aban

Reputation: 904

Instead of

<TextView
    android:id="@+id/PhoneLabel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:freezesText="true"
    android:gravity="center|left"
    android:marqueeRepeatLimit="marquee_forever"
    android:paddingLeft="5dp"
    android:scrollHorizontally="true"
    android:singleLine="true"
    android:text="XXX"
    android:textColor="#2CABE2"
    android:textSize="30sp"
    android:textStyle="bold" />

use:

<TextView
    android:id="@+id/PhoneLabel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dp"
    android:singleLine="true"
    android:text="XXX"
    android:textColor="#2CABE2"
    android:textStyle="bold" />

Upvotes: 1

velis
velis

Reputation: 10025

Your problem stems from the fact that you are using layout_weight properties on your layouts. This way all layouts nicely shrink / expand depending on number of phone numbers, but they also won't look too good if you add even more numbers.

I would suggest that you use layout_height="wrap_content" for all horizontal LinearLayouts. Your screen elements will have a more defined height then and ListView will not be able to claim too much screen space for itself any more.

Upvotes: 0

Digvesh Patel
Digvesh Patel

Reputation: 6533

<?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:orientation="vertical" >

<LinearLayout
    android:id="@+id/LayoutContactNumber"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".20"
    android:background="@drawable/blackbg"
    android:gravity="left|center"
    android:orientation="horizontal" >

    <com.res.dese.number.ResizableImageView
        android:id="@+id/CImage"
        android:layout_width="120px"
        android:layout_height="120px"
        android:padding="5dp"
        android:scaleType="fitXY"
        android:src="@drawable/no_pic" />

    <TextView
        android:id="@+id/PhoneLabel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:freezesText="true"
        android:gravity="center|left"
        android:marqueeRepeatLimit="marquee_forever"
        android:paddingLeft="5dp"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:text="XXX"
        android:textColor="#2CABE2"
        android:textSize="30sp"
        android:textStyle="bold" />
</LinearLayout>

<ImageView
    android:id="@+id/whiteline"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:src="@drawable/whiteline" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".65"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="#007FFF"
        android:marginBottiom="20dp"
        android:dividerHeight="3dp" >
    </ListView>
</LinearLayout>

<ImageView
    android:id="@+id/whiteline"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:src="@drawable/whiteline" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".15"
    android:gravity="center"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/okandeditlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <LinearLayout
            android:id="@+id/editContactlinearlayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight=".50"
            android:orientation="horizontal"
            android:paddingRight="2dp" >

            <ImageView
                android:id="@+id/editnumber"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/newedit" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayoutDeleteConatct"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight=".50"
            android:orientation="horizontal"
            android:paddingLeft="2dp" >

            <ImageView
                android:id="@+id/del"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/newdelete" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

Upvotes: 0

user2689294
user2689294

Reputation: 129

you can add to the listview android:layout_marginBottom="10dp"

Upvotes: 0

Pararth
Pararth

Reputation: 8134

Can you post your activity code also. Will edit my answer then.

An option is to use getWindow() and use its setLayout, setMargin and more...

 //after setContentView, set the Layout parameters to fill parent (should make the dialog full screen)
    getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

I have used the properties from getWindow() and set margins, provide padding and position, alignment for my Dialog Activity.

Another option is adding some padding (through values in res dimens xml) to your parent layout.

Upvotes: 0

kiran boghra
kiran boghra

Reputation: 3822

Give this property to listview

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:divider="#007FFF"
    android:dividerHeight="3dp" >
</ListView>

And remove other weight from other all the views and set height as wrap_content so listview will get remaining area after that all elements will set properly.

if you give

android:layout_height="0dp"
android:layout_weight="1"

to element than it will occupy only remaining area.

Upvotes: 2

icaneatclouds
icaneatclouds

Reputation: 1170

You could give this a try. Put this in your styles.xml:

  <style name="CustomDialog" parent="@android:style/Theme.Dialog">
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:windowIsFloating">false</item>
</style>

Lets say you have your dialogxml.xml now. So here is the code for calling the dialog:

public void openDialog() {
        LayoutInflater inflater = (LayoutInflater) getLayoutInflater();

        View customView = inflater.inflate(R.layout.dialogxml, null);

        // Build the dialog
        Dialog dialogBuilder = new Dialog(this, R.style.CustomDialog);
        dialogBuilder.setContentView(customView);


        dialogBuilder.show();
    }

Give it a try and tell me if it didn't work. :)

Upvotes: 0

Related Questions