开发者社区> 问答> 正文

android中自定义view高宽使用match_parent后不能自适应,请求?400报错

android中自定义view高宽使用match_parent后不能自适应,请求解答? 400 报错

如题,我自定义了一个view之后将view放在中间,view的下面有几个按钮。但是不管怎么设置我在view上画的path总是会画到下面的按钮上面,请问一下这个问题如何解决啊。我感觉自己设定的view设定高宽的时候并没有测量到下面的button。

ps:

展开
收起
爱吃鱼的程序员 2020-06-05 13:14:36 967 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    引用来自“小又鸟”的评论

    说两个问题:1上面的文字部分,用一个TextView可以实现.2你自定义的view设了bellow,所以会铺满最后一个TextView的下方:有两种情况:如果放Button的LinearLayout先写,自定义的view会覆盖在LinearLayout的上方,如果先写自定义的View,那么LinearLayout会覆盖在自定义的view,如果要使自定义view在中间而不相互覆盖,需要再给LinearLayout设置bellow

    我的我的,这样也不行,我亲自试了下,LinearLayout不要动,给自定义View设置above.

    <com.example.yan.indoorlocation13.OrientationView
            android:layout_below="@id/label_last_step_length"
            android:layout_above="@+id/radioGroup"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/orientation_view"
            />



    ######对的这样是可以的,谢谢啦######你这个view应该是铺满屏幕的######回复 @小又鸟 : 好的,在我的回复里面,我不知道怎么修改答案,(-__-)b######回复 @jimielee : 把你的布局文件贴出来我看看######那请问一下有什么方式可以解决这个问题啊######

    <RelativeLayout
        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:id="@+id/rly"
        >
    
       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:id="@+id/label_step"
           android:text="@string/label_step"
    
           android:layout_alignParentTop="true"
           android:layout_alignParentStart="true" />
    
        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:id="@+id/total_steps"
    
            android:layout_toEndOf="@id/label_step" />
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/label_distance"
            android:text="@string/label_distance"
            android:layout_below="@id/label_step"
            android:layout_alignParentStart="true" />
    
        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:id="@+id/total_distance"
            android:layout_below="@id/total_steps"
            android:layout_toEndOf="@id/label_distance" />
    
        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:id="@+id/label_last_step_length"
            android:text="@string/label_last_step_length"
            android:layout_below="@id/label_distance"
            android:layout_alignParentStart="true" />
    
        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:id="@+id/step_length"
            android:layout_below="@id/total_distance"
            android:layout_toEndOf="@id/label_last_step_length" />
    
    
        <LinearLayout
            android:layout_alignParentBottom="true"
            android:id="@+id/radioGroup"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#ddefe1"
            android:orientation="horizontal"
            >
    
            <Button
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:id="@+id/start_end"
                android:text="@string/start"
                android:background="#ffffff"
                android:layout_weight="0.25"
                />
    
            <Button
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:id="@+id/reset"
                android:text="@string/reset"
                android:background="#ffffff"
                android:layout_weight="0.25"
                />
    
            <Button
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/save"
                android:id="@+id/save"
                android:background="#ffffff"
                android:layout_weight="0.25"
                />
    
    
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/give_up"
                android:text="@string/give_up"
                android:background="#ffffff"
                android:layout_weight="0.25" />
    
        </LinearLayout>
    
        <com.example.yan.indoorlocation13.OrientationView
            android:layout_below="@id/label_last_step_length"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/orientation_view"
            />
    
    </RelativeLayout>


    ######说两个问题:1上面的文字部分,用一个TextView可以实现.2你自定义的view设了bellow,所以会铺满最后一个TextView的下方:有两种情况:如果放Button的LinearLayout先写,自定义的view会覆盖在LinearLayout的上方,如果先写自定义的View,那么LinearLayout会覆盖在自定义的view,如果要使自定义view在中间而不相互覆盖,需要再给LinearLayout设置bellow######我这么设置之后发现下面全部为自定义的view,linearlayout被挤成了一条线。。。
    2020-06-05 13:14:48
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
58同城Android客户端Walle框架演进与实践之路 立即下载
Android组件化实现 立即下载
蚂蚁聚宝Android秒级编译——Freeline 立即下载