Java 如何动态获取中心视点组布局?

Java 如何动态获取中心视点组布局?,java,android,kotlin,Java,Android,Kotlin,这是我的密码 var graphHeight = parentLayout.height var graphPointView = LayoutInflater.from(context).inflate(R.layout.view_graph_point, null, false) graphPointView.y =(graphHeight / 2f) graphView.addView(graphPointView) 而且 灰线位于视图组布局的中心位置,为什么红点不在视图组布局的中心

这是我的密码

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"/>

我的代码有什么问题


这很可能是布局的“问题”,而不是代码的问题。我猜您的容器没有拉伸到最大宽度。只需确保它的宽度是
match\u parent
而不是
wrap\u content
,应该是这样。

显示您的
R.layout。查看图形\u point
xmlI已添加@红段子是
图形\圆\点
png或形状可绘制,如果形状可绘制,则发布代码。还尝试在高度和宽度上使用wrap_内容。而
@drawable/graph_round_点
?我将高度和宽度更改为wrap_内容。但图形点仍在灰线以下。T.T…..请检查graph\u round\u point.xml