简体   繁体   English

具有自定义布局的Android对话框:未完全显示

[英]Android dialog with custom layout: not fully shown

I'm creating an app that shows a GridView with photos and some TextViews with details regarding the photo (uploader, description). 我正在创建一个显示带有照片的GridView和带有有关照片的详细信息(上传器,描述)的TextView的应用程序。 When the user clicks on a GridView item, it is supposed to show the picture bigger with some details in TextViews (just like on Facebook when you click on an image). 当用户单击GridView项时,应该在TextViews中显示带有某些细节的更大图片(就像单击图像时在Facebook上一样)。

That's why I decided to implement this with an Alert Dialog and a custom layout. 这就是为什么我决定通过“警报对话框”和自定义布局来实现这一点的原因。 The layout is the following, just an ImageView and a TextView to the right of the picture. 下面是布局,图片的右边是ImageView和TextView。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    tools:context="com.example.handmadecommunity.FullImageActivity" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin" >

        <ImageView
            android:id="@+id/picture"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:contentDescription="@string/contentDescriptor"
            android:maxHeight="500dp"
            android:maxWidth="500dp"
            android:src="@drawable/test" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/picture"
            android:layout_marginLeft="41dp"
            android:layout_marginTop="24dp"
            android:layout_toRightOf="@+id/picture"
            android:ellipsize="marquee"
            android:gravity="left"
            android:scrollHorizontally="true"
            android:singleLine="false"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    </RelativeLayout>

</ScrollView>

I create my alert dialog the following way (just to point out, this is in a fragment, that's why the getActivity()) 我通过以下方式创建警报对话框(只是指出,这是一个片段,这就是getActivity()的原因)

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View layout = inflater.inflate(R.layout.activity_full_image, null);

TextView description = (TextView) layout.findViewById(R.id.textView1);
description.setText(desc);

alertDialogBuilder.setTitle(title).setView(layout).setCancelable(true);
AlertDialog alert = alertDialogBuilder.create();
alert.show();

My problem can be shown on this pic http://imgur.com/OGQRyse . 我的问题可以在此图片http://imgur.com/OGQRyse上显示

Am I missing something on the layout or code? 我在布局或代码上缺少什么吗?

Your ImageView is too big it is pushing TextView out of the screen try placing it below ImageView 您的ImageView太大,正将TextView推出屏幕,请尝试将其放在ImageView下方

<TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:gravity="left"
        android:scrollHorizontally="true"
        android:singleLine="false"
        android:text="Hello "
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_below="@+id/picture"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM