Ich versuche, zwei TextView
One ist innerhalb HorizontalScrollView
, und beide sind Kinder von LinerLayout
.getBaseline von TextView gibt -1
Wenn ich versuche getBaseLine
von TextView
innerhalb onWindowAttached
von RecyclerView Adapter ruft immer -1 zurück.
Ja, die übergeordnete Ansicht von TextView
, LinerLayout
hat android:baselineAligned="true"
Edit: Hinzufügen von Code
Layout-
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="6dp"
android:paddingEnd="10dp"
android:baselineAligned="true"
android:paddingStart="10dp"
android:paddingTop="10dp">
<TextView
android:id="@+id/outerTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical" />
<HorizontalScrollView
android:id="@+id/scrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/inlineTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
/>
</HorizontalScrollView>
</LinearLayout>
-Code in RecyclerView Adapter
@Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder)
{
super.onViewAttachedToWindow(holder);
if(holder instanceof MyHolder)
{
dostuff((MyHolder)holder);
}
}
private void dostuff(QACommentViewHolder holder)
{
int baseline = holder.outerTextView.getBaseline();
}
Geben Sie Ihren Code ein. – Sharj
@Sharj Bitte beachten Sie die Änderung. – q126y