Я использую Android Studio. Мой проект предполагает получение некоторых данных через BLE и отображение их на экране в линейной компоновке.Как увеличить размер линейной компоновки во время выполнения программно?
Мой основной код активности для добавления Вид:
dataLayout.addView(view, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
Функция определяется как:
addView(dataEdit, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1));
В моем файле XML, необходимая часть выглядит следующим образом:
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
android:id="@+id/dataLayout"
android:fillViewport="true">
</LinearLayout>
EDIT : Весь файл xml выглядит так:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:focusable="true"
android:focusableInTouchMode="true"
android:baselineAligned="true">
<TextView
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textView2"
android:text="Find Device"
android:layout_marginTop="5dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scanStatus" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Scan"
android:id="@+id/scan"
android:layout_gravity="center_horizontal"
android:enabled="false" />
<TextView
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textView4"
android:layout_marginTop="5dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/deviceInfo" />
<TextView
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textView3"
android:text="Connect Device"
android:layout_marginTop="5dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/connectionStatus" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Connect"
android:id="@+id/connect"
android:layout_gravity="center_horizontal"
android:enabled="false" />
</LinearLayout>
<TextView
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textView7"
android:text="Receive"
android:textColor="#0B0101"
android:layout_marginTop="5dip" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Clear Data"
android:textColor="#FFFCFC"
android:id="@+id/clearData"
android:layout_gravity="center_horizontal"
android:singleLine="false" />
<TextView
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textView9"
android:text="Graphs"
android:layout_marginTop="5dip" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Plot"
android:id="@+id/Plot"
android:layout_weight="1"
android:layout_marginTop="2dip"
android:singleLine="false"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Distance:"
android:textColor="#0B0101"
android:id="@+id/textView8" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
android:id="@+id/dataLayout"
android:fillViewport="true">
</LinearLayout>
</LinearLayout>
</ScrollView>
Проблема заключается в том, что на экране отображаются только первые 9 значений принятых данных. После этого, даже когда я просматриваю экран, я не вижу никаких значений. Я хочу прокручивать экран и видеть все полученные значения.
Любая помощь будет оценена по достоинству.
Я обновил свой ответ, сообщите нам, если он работает! – bonnyz
@bonnyz Я пробовал код, который вы обновили. Это сделало макет более централизованным и лучше выглядящим, но проблема отображения только первых нескольких значений существует. – user3863537