Android的画廊动态调整高度 [英] Android gallery dynamically resize height

查看:198
本文介绍了Android的画廊动态调整高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要让水平画廊进行自定义视图:
例如想拥有的产品以其的描述,价格和照片的数组,
我建立自定义布局,并覆盖getView和适配器。

I want to make horizontal gallery to perform custom views: for example a want to have an array of products with its' description, price and photo, I build custom layout and override getView and adapter.

说明文字可以过大,我返回它的只有小部分负荷的观点。有一个按钮,多,扩大了这一观点。下面的画廊有一些按键的另一个布局来看,控制等。

Description text can be too large and I return only small portion of it and load to the view. There is a button "more" to expand this view. Below the gallery there is an another layout view with some buttons, controls etc.

OnMoreButtonClick我只设置全文描述的TextView。画廊的高度我wrapcontent,我认为它具有动态改变大小。

OnMoreButtonClick I only set full text to the description TextView. Gallery height I wrapcontent and I think it has to change size dynamically.

顺便说一句,如果我加载全文无短单 - 一切都好

BTW if I load the full text without short one - everything is ok.

这是应用程序的主屏幕上,当我preSS按钮,我想画廊项目向下伸展拉TimeAndDatePicker了下来。

This is main screen of app, when I press button I want gallery item to stretch down and pull TimeAndDatePicker down.

但是,当我preSS它,我只能看到:

But when I press it I can only see:

如果我没有装入小的一切全文是确定的:

And if I load the full text without small one everything is ok:

main.xml中:

Main.xml:

<?xml version="1.0" encoding="utf-8"?>

android:layout_width="fill_parent"
android:id = "@+id/scene"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/main_background" >

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
            <ru.human.samples.CustomGallery
              android:id="@+id/galleryUnique"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:gravity="center"
              android:spacing="1dp" android:unselectedAlpha="255.0" android:visibility="visible" android:fadingEdge="none"/>
           <DatePicker
        android:id="@+id/datePicker1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    </LinearLayout>



</ScrollView>

和galleryItem XML:

And galleryItem xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="15dp"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        style="@style/PriceText"
        android:text="Medium Text"/>

</LinearLayout>

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    style="@style/BodyText"
    android:text="TextView" />

 <TextView
    android:id="@+id/description"
    android:layout_width="match_parent"
    style="@style/BodyText"
    android:text="Medium Text"
    android:layout_height="wrap_content" />

 <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

推荐答案

有一个黑客在我的情况。

There is one "hack" in my case.

我把多一个的LinearLayout画廊,使其默认和画廊FitParent WrapContent,
当我点击更多按钮,我展开布局的高度(previous高度+ countlines新的TextView * sizeoftext的)。

I put gallery in one more LinearLayout, make it WrapContent by default and Gallery FitParent, when i click "more" button i expand the Layout height (previous height + countlines of new textview * sizeoftext).

这篇关于Android的画廊动态调整高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆