Я попытался установить размеры GraphView, чтобы они были прямоугольными angular в соотношении 2: 1, и я хочу, чтобы он также оставался в ландшафте, используя match_parent
ширину. Я хочу установить layout_height
для имени layout_width
, то есть layout_height = layout_width / 2
.
Это моя текущая конфигурация:
активность. xml
<?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">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.jjoe64.graphview.GraphView
android:id="@+id/graph"
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_gravity="center"
android:gravity="center"/>
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
Я пытался изменить его программно, но он исчез:
код. java
private GraphView graph;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_graph);
graph = findViewById(R.id.graph);
ViewGroup.LayoutParams param = graph.getLayoutParams();
param.height = param.width/2;
graph.setLayoutParams(param);
}