【问题标题】:how to dynamically get center point of view group layout?如何动态获取中心点组布局?
【发布时间】:2018-06-21 08:56:04
【问题描述】:

这是我的代码

var graphHeight =  parentLayout.height
var graphPointView = LayoutInflater.from(context).inflate(R.layout.view_graph_point, null, false)
graphPointView.y =(graphHeight / 2f)
graphView.addView(graphPointView)

还有……

灰线在视图组布局的中心位置,为什么红点不在视图组布局的中心?我想把它放在中心位置。 (如灰线)

我的代码有什么问题?

view_graph_point.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/graph_point_view"
    android:layout_width="10dp"
    android:layout_height="10dp"
    android:layout_centerHorizontal="true"
    android:background="@drawable/graph_round_point"
    xmlns:android="http://schemas.android.com/apk/res/android" />

graph_round_point.xml

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="#A04000"/>
<stroke android:width="1dp" android:color="#fff" />
<size android:width="12dp" android:height="12dp"/>

【问题讨论】:

  • 显示你的R.layout.view_graph_point xml
  • 我添加了。 @洪端
  • 是 graph_round_point png 或 shape drawable,如果 shape 则发布代码。也尝试在高度和宽度上使用 wrap_content。
  • 和@drawable/graph_round_point?
  • 我将高度和宽度更改为 wrap_content 。但图形点仍在灰线下方。 T.T.....请检查graph_round_point.xml

标签: java android kotlin


【解决方案1】:

我的代码有什么问题

这很可能是您的布局“问题”,而不是代码。我猜你的容器没有拉伸到最大宽度。只要确保它的宽度是match_parent 而不是wrap_content 就可以了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    • 2014-08-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多