我有一个链,ConstraintLayout其中包含一个TextView,一个ImageView和另一个TextView(不需要自动调整大小)。我希望它们三个在父容器中垂直居中(即到左/右的距离相同)。
我要TextView自动调整大小,以使文本不会溢出。我不能将autosize layout_width设置为wrap_content(什么也不会发生,并且文本不会调整大小)。我也不能设置一个固定值layout_width,因为文本不是很长时,多余的空间会导致对齐问题。
无论如何,可以通过XML来执行此操作,还是应该实现自己的自动调整大小行为?
我想让一个LinearLayout(我正在动态添加项目)在 scrollable 内滚动RecyclerView。在启动时,我最初可以看到一个小滚动条(表明它是一个可滚动视图,在几秒钟内消失)。尝试了 appCompat NestedScrollView 以及 enable nestedScrollingEnabled,但没有成功。我怎样才能在LinearLayout里面滚动RecyclerView?
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="300dp"
android:fillViewport="true"
android:nestedScrollingEnabled="true">
<LinearLayout
android:id="@+id/playerlist_linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="7dp"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
RecyclerView 代码
<android.support.v7.widget.RecyclerView
android:id="@+id/messagesListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:nestedScrollingEnabled="false"/>
Run Code Online (Sandbox Code Playgroud)
更新:我发现滚动确实有效,但前提是我向鼠标发送垃圾邮件或在滚动视图中快速点击。只要按住鼠标,它就会变得专注并允许滚动。真的很奇怪。