
각 줄의 y값이랑 버튼의 y값이랑 일치시키고싶었습니다.
점점 버튼이 추가되면서 버튼이 줄위로 줄의y값보다 작게, 지정되고있습니다.
(위에서 두번째 라인은 왼쪽에서 두번째버튼이랑 같은 높이에, 이런식으로.....)
밑에는 이에대한 소스입니다.
어느부분이 문제일지 알려주시면 안될까요?
xml -
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
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="200dp"
android:id="@+id/rootView"
>
<LinearLayout
android:id="@+id/frontView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="horizontal"></LinearLayout>
<LinearLayout
android:id="@+id/backView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="vertical"></LinearLayout>
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
java-
package com.dyco.testapp;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
LinearLayout frontLayout,backLayout;
RelativeLayout rootLayout;
ArrayList<Integer> linesYs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rootLayout = findViewById(R.id.rootView);
frontLayout = findViewById(R.id.frontView);
backLayout = findViewById(R.id.backView);
frontLayout.setX(rootLayout.getX());
frontLayout.setY(rootLayout.getY());
backLayout.setX(frontLayout.getX());
backLayout.setY(frontLayout.getY());
linesYs = new ArrayList<>();
backLayout.post(new Runnable() {
@Override
public void run() {
LinearLayout.LayoutParams lineParm = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 2);
int lineSeed = Math.round(frontLayout.getHeight() / 10);
for (int i = 0; i < 10; i++) {
LinearLayout line = new LinearLayout(backLayout.getContext());
line.setBackgroundColor(Color.BLACK);
backLayout.addView(line, lineParm);
line.setY(lineSeed * i);
linesYs.add((int) line.getY());
}
for (int i:linesYs) {
Button btn = new Button(frontLayout.getContext());
btn.setText("tt");
btn.setBackgroundColor(Color.BLUE);
frontLayout.addView(btn);
btn.setY(i);
}
}
});
}
}