Java Android:布局没有被添加到彼此的下方
我正在尝试在彼此下方添加多个约束。但他们似乎处于同一立场。(见图) 问题:如何使约束条件彼此低于对方 现在发生了什么: 例1: 例2: 它应该是什么样子的: Activity.javaJava Android:布局没有被添加到彼此的下方,java,android,android-layout,Java,Android,Android Layout,我正在尝试在彼此下方添加多个约束。但他们似乎处于同一立场。(见图) 问题:如何使约束条件彼此低于对方 现在发生了什么: 例1: 例2: 它应该是什么样子的: Activity.java String response = (String) databaseManager.execute(phpLocation, parameters).get(); List<Review> listOfReviews = (List<Review>) Entity
String response = (String) databaseManager.execute(phpLocation, parameters).get();
List<Review> listOfReviews = (List<Review>) EntityConverter.getInstance().jsonToObject(response,
new TypeToken<Collection<Review>>(){}.getType());
int totalscore = 0;
int amountOfReviews = 0;
RelativeLayout relativeLayoutReviews = (RelativeLayout) findViewById(R.id.relativeLayoutReviews);
for(Review r : listOfReviews) {
LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = vi.inflate(R.layout.reviewtemplate, null);
v.setId(amountOfReviews);
TextView name = (TextView) v.findViewById(R.id.textViewReviewName);
name.setText(r.getName());
RatingBar ratingBar = (RatingBar) v.findViewById(R.id.ratingBarReviewScore);
ratingBar.setRating(r.getScore());
totalscore += r.getScore();
TextView ratingText = (TextView) v.findViewById(R.id.textViewReviewText);
ratingText.setText(r.getReviewtext());
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
if (amountOfReviews != 0) {
// add the rule that places your button below your EditText object
params.addRule(RelativeLayout.BELOW, v.getId() -1);
}
relativeLayoutReviews.addView(v, amountOfReviews);
amountOfReviews++;
}
String response=(String)databaseManager.execute(phpLocation,parameters.get();
List listOfReviews=(List)EntityConverter.getInstance().jsonToObject(响应,
新的TypeToken(){}.getType());
整数总分=0;
int amountOfReviews=0;
RelativeLayout relativeLayoutReviews=(RelativeLayout)findViewById(R.id.relativeLayoutReviews);
审查(r:审查清单){
LayoutInflater vi=(LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT\u INFLATER\u SERVICE);
视图v=vi.充气(R.layout.reviewtemplate,空);
v、 setId(amountOfReviews);
TextView名称=(TextView)v.findViewById(R.id.textViewReviewName);
name.setText(r.getName());
RatingBar RatingBar=(RatingBar)v.findViewById(R.id.ratingBarReviewScore);
ratingBar.setRating(r.getScore());
totalscore+=r.getScore();
TextView评级text=(TextView)v.findViewById(R.id.textViewReviewText);
ratingText.setText(r.getReviewtext());
RelativeLayout.LayoutParams params=新的RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_内容,RelativeLayout.LayoutParams.WRAP_内容);
如果(视图数量!=0){
//添加将按钮放置在EditText对象下方的规则
params.addRule(RelativeLayout.down,v.getId()-1);
}
relativeLayoutReviews.addView(v,amountOverViews);
amountOfReviews++;
}
reviewtemplate.xml(我正在尝试插入的内容)
RelativeLayout,它将包含所有评论
<RelativeLayout
android:id="@+id/relativeLayoutReviews"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginStart="20dp"
android:layout_marginTop="1dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
</RelativeLayout>
您应该使用线性布局进行布局审查,方向垂直 编辑: 使用阿提布特 你能试试吗
<RelativeLayout
android:id="@+id/relativeLayoutReviews"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginStart="20dp"
android:layout_marginTop="1dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="spread" >
</RelativeLayout>
希望这能有所帮助。发生这种情况是因为根(父)布局是相对的,而不是线性布局 添加到RelativeLayout中的子视图不会一个接一个地定位,因为它们的父视图根据它们的子属性来布置它们的定位(因此,为什么定位是相对的)
将它们添加到具有垂直方向的线性布局中。是否可以使用约束布局进行此操作?谢谢您的回答,但我认为链接是协调布局的一部分,你把它放在RelativeLayout标记之间。我暂时不能尝试,但你必须能够在相对布局中使用此属性。我尝试了,但我得到了一个错误,即“chain_spread”不是一个已知的符号。我尝试使用“spead”,我再也没有编译错误了。但不幸的是,协调人的布局仍然处于相同的位置。
<RelativeLayout
android:id="@+id/relativeLayoutReviews"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginStart="20dp"
android:layout_marginTop="1dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="spread" >
</RelativeLayout>