我正在尝试垂直布局两个线性布局,第一个布局有时有一堵文字墙,有时又很短。而第二个线性布局,也有两个垂直堆叠的按钮。
如果文本很短,我如何获得带有按钮的第二个线性布局以留在屏幕底部,或者如果文本很长则位于段落末尾?
编辑:抱歉,没有立即放置 xml。是这样的
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical">
<TextView
android:id="@+id/text_pdtwo_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="2dp"
android:layout_marginStart="2dp"
android:lineSpacingExtra="5dp"
android:text="@string/text_pd_two_intro_title"
android:textColor="#000"
android:textSize="23sp" />
<ImageView
android:id="@+id/img_pd_two_headshot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="16dp"
android:src="@drawable/img_pd_two_sample" />
<TextView
android:id="@+id/text_pd_two_review_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginStart="2dp"
android:lineSpacingExtra="5dp"
android:lineSpacingMultiplier="1.3"
android:text="Lorem ipsum dolor sit amet.."
android:textColor="#000"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:layout_marginBottom="16dp"
android:orientation="vertical">
<Button
android:id="@+id/button_pd_two_take_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:lineSpacingExtra="5dp"
android:layout_marginBottom="16dp"
android:text="@string/button_pd_two_take_photo"
android:textColor="#000"
android:textSize="15sp" />
<Button
android:id="@+id/button_pd_two_select_gallery"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:lineSpacingExtra="5dp"
android:text="@string/button_pd_two_select_gallery"
android:textColor="#000"
android:textSize="15sp" />
<Button
android:id="@+id/button_pd_two_submit_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="16dp"
android:lineSpacingExtra="5dp"
android:text="@string/button_pd_two_submit_photo"
android:textColor="#000"
android:visibility="gone"
android:textSize="15sp" />
<Button
android:id="@+id/button_pd_two_cancel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:lineSpacingExtra="5dp"
android:text="@string/button_pd_two_cancel"
android:textColor="#fff"
android:visibility="gone"
android:textSize="15sp" />
</LinearLayout>
</RelativeLayout>
文字很短的时候是这样的,很好
但是当文本很长时,它会变成这样......我希望它出现在文本的末尾并且可能在用户实际点击按钮之前向下滚动......
最佳答案
如果您不想在您可以通过这种方式使用的布局中添加 ScrollView,那么任何一个 View (TextView 或 Button)都不会与其他 View 重叠:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:layout_above="@+id/bottom_layout">
<TextView
android:id="@+id/text_pdtwo_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="2dp"
android:layout_marginStart="2dp"
android:lineSpacingExtra="5dp"
android:text="@string/text_pd_two_intro_title"
android:textColor="#000"
android:textSize="23sp" />
<ImageView
android:id="@+id/img_pd_two_headshot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="16dp"
android:src="@mipmap/ic_launcher" />
<TextView
android:id="@+id/text_pd_two_review_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginStart="2dp"
android:lineSpacingExtra="5dp"
android:lineSpacingMultiplier="1.3"
android:text="Lorem ipsum dolor sit amet.."
android:textColor="#000"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/bottom_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:layout_marginBottom="16dp"
android:orientation="vertical">
<Button
android:id="@+id/button_pd_two_take_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:lineSpacingExtra="5dp"
android:layout_marginBottom="16dp"
android:text="button_pd_two_take_photo"
android:textColor="#000"
android:textSize="15sp" />
<Button
android:id="@+id/button_pd_two_select_gallery"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:lineSpacingExtra="5dp"
android:text="button_pd_two_select_gallery"
android:textColor="#000"
android:textSize="15sp" />
<Button
android:id="@+id/button_pd_two_submit_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="16dp"
android:lineSpacingExtra="5dp"
android:text="button_pd_two_submit_photo"
android:textColor="#000"
android:visibility="gone"
android:textSize="15sp" />
<Button
android:id="@+id/button_pd_two_cancel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:lineSpacingExtra="5dp"
android:text="button_pd_two_cancel"
android:textColor="#fff"
android:visibility="gone"
android:textSize="15sp" />
</LinearLayout>
</RelativeLayout>
如果您的文本会增加,我们需要通过此代码在文本中添加滚动:
/*For scrolling TextView*/
text_pd_two_review_content.setMovementMethod(new ScrollingMovementMethod());
text_pd_two_review_content.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// Disallow the touch request for parent scroll on touch of child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
关于android - 垂直布局按钮和文本墙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47461618/