小编bra*_*ree的帖子

动态添加视图后WRAP_CONTENT无法正常工作

我正在尝试创建一个动态显示一系列自定义视图的片段.此布局的主要内容是嵌套在LinearLayout中的RelativeLayout(以水平为中心),嵌套在ScrollView中.

RelativeLayout有一些TextView和一个9补丁ImageView,可以通过动态添加的自定义视图进行扩展.但是,图像(下面的achievement_bgImageView)最终会以屏幕大小结束,即使我添加了适当数量的自定义视图,也不会尊重其父RelativeLayout的大小.当我手动设置achievement_mainLayout的大小时,图像可以很好地缩放(请参阅下面注释掉的行),但如果我尝试让RelativeLayout的wrap_content处理自己的大小调整,则无效.

ScrollView IS尊重RelativeLayout的大小,因为所有内容都存在,它只是不伸展以匹配此时内容的imageView.

任何帮助将不胜感激...我的手动计算似乎不足以考虑不同的设备,尽管我考虑到屏幕密度,我手动强迫RelativeLayout到一个恒定的宽度.

值得注意的是,RelativeLayout的测量大小始终等于屏幕的高度,无论其内容的总和是大于还是小于该高度.所以,从本质上讲,WRAP_CONTENT根本就没有做它应该做的事情.我没有引用RelativeLayout的任何边缘,所以循环依赖应该不是问题.

fragment_achievements.xml

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

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true" >

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal">

        <RelativeLayout
                android:layout_width="320dp"
                android:layout_height="wrap_content"
                android:id="@+id/achievements_mainLayout">

            <ImageView
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:id="@+id/achievements_bgImageView"
                    android:src="@drawable/bkg_achievements9"
                    android:adjustViewBounds="true"
                    android:layout_marginLeft="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginRight="8dp"
                    android:layout_centerHorizontal="true"
                    android:scaleType="fitXY"/>

            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Name Field"
                    android:id="@+id/achievements_nameTextView"
                    android:layout_alignParentTop="true"
                    android:layout_alignParentLeft="true"
                    android:layout_marginLeft="28dp"
                    android:layout_marginTop="30dp"/>

            <ImageView
                    android:layout_width="52dp"
                    android:layout_height="52dp"
                    android:id="@+id/achievements_avatarImageView"
                    android:layout_below="@+id/achievements_nameTextView"
                    android:layout_alignLeft="@+id/achievements_nameTextView"
                    android:src="@drawable/achieve_avatar"
                    android:layout_marginTop="5dp"/>

            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="Top Moment:"
                    android:id="@+id/textView2"
                    android:layout_alignBottom="@+id/achievements_avatarImageView"
                    android:layout_toRightOf="@+id/achievements_avatarImageView"
                    android:layout_marginBottom="16dp"
                    android:layout_marginLeft="4dp"
                    android:textSize="12dp"/>

            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="Me Overall:"
                    android:id="@+id/textView3"
                    android:layout_alignTop="@+id/textView2"
                    android:layout_alignLeft="@+id/textView2"
                    android:layout_marginTop="16dp"
                    android:textSize="12dp"/>

            <TextView
                    android:layout_width="52dp"
                    android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android android-layout

35
推荐指数
4
解决办法
2万
查看次数

Android Studio停止按钮没有停止

这必须是一个愚蠢的问题,但在Android Studio 0.3.2中我试图在特定位置停止我的应用程序,以便我可以在下次重新启动应用程序时模拟特定的自动恢复功能(模仿失败).但是,当我点击调试器中的停止按钮时,它只是断开连接并且应用程序继续运行.我误解停止按钮的作用了吗?有没有办法从调试器合法地杀死应用程序,就像你可以在XCode中的iOS应用程序一样?

android android-studio

14
推荐指数
1
解决办法
6813
查看次数

标签 统计

android ×2

android-layout ×1

android-studio ×1