[英]How to align buttons side by side in scroll view?
I just started using android studio.. I am trying to align ImageButtons inside a scroll view side by side, but i cannot put them side by side, neither can i resize them from the left side. 我刚开始使用android studio ..我试图将ImageButtons并排放在滚动视图中,但我不能将它们并排放置,我也不能从左侧调整它们。 How do i align them side by side?
我如何并排排列?
I already tried the solution given in one of the answers: Aligning TextView Side By Side Inside A ScrollView Inside a Linear Layout but it didn't work 我已经尝试了其中一个答案给出的解决方案: 在线性布局内部ScrollView内部并排对齐TextView但它不起作用
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".StoryIndex">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageButton
android:id="@+id/titlee"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/black"
app:srcCompat="@drawable/alami1" />
<ImageButton
android:id="@+id/imageButton8"
android:layout_width="375dp"
android:layout_height="116dp"
android:background="@android:color/black"
app:srcCompat="@drawable/alami2" />
<ImageButton
android:id="@+id/imageButton9"
android:layout_width="195dp"
android:layout_height="169dp"
app:srcCompat="@drawable/alami3" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
I want the Image buttons to be side by side, but they are in rows, on top of each other.. but it shows like the one in picture: Image of the design view Thanks. 我希望图像按钮并排,但它们是成排的,彼此叠加..但它显示的像图片中的那个:设计视图的图像谢谢。
You have to change the orientation in LinearLayout from vertical to horizontal. 您必须将LinearLayout中的方向从垂直更改为水平。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
Try this 尝试这个
<LinearLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
//The question you mentioned can be obtained by using weightSum
android:weightSum="15">
//replace src ic_launcher_background by your drawable source.
<ImageButton
android:id="@+id/titlee"
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:src="@drawable/ic_launcher_background" />
<ImageButton
android:id="@+id/imageButton8"
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:src="@drawable/ic_launcher_background" />
<ImageButton
android:id="@+id/imageButton9"
android:layout_width="0dp"
android:layout_weight="5"
android:background="@android:color/black"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher_background"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Try this and let me know. 试试这个,让我知道。 Happy coding.
快乐的编码。
<LinearLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="15">
<ImageButton
android:id="@+id/imageButtonOne"
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:src="@drawable/ic_launcher_background" />
<ImageButton
android:id="@+id/imageButtonTwo"
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:src="@drawable/ic_launcher_background" />
<ImageButton
android:id="@+id/imageButtonThree"
android:layout_width="0dp"
android:layout_weight="5"
android:background="@android:color/black"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher_background"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Try this if you still find any issue, let me know. 如果您仍然发现任何问题,请尝试此操作,请告知我们。
Show the Image buttons to be side by side, and in rows. 将图像按钮显示为并排,并按行显示。
Change the orientation of LinearLayout
from vertical
to horizontal
. 将
LinearLayout
的方向从vertical
更改为horizontal
。
Please try below code: 请尝试以下代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:id="@+id/titlee"
android:layout_weight=".3"
android:layout_width="0dp"
android:layout_height="116dp"
android:background="@android:color/black"
app:srcCompat="@drawable/stars_one"
android:layout_margin="4dp"/>
<ImageButton
android:layout_weight=".4"
android:id="@+id/imageButton8"
android:layout_width="0dp"
android:layout_height="116dp"
android:background="@android:color/black"
app:srcCompat="@drawable/stars_one"
android:layout_margin="4dp"/>
<ImageButton
android:layout_weight=".3"
android:id="@+id/imageButton9"
android:layout_width="0dp"
android:layout_height="116dp"
app:srcCompat="@drawable/stars_one"
android:layout_margin="4dp"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
The output of above code is like: 上面代码的输出如下:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.