現在、スクロールビューで設定メニューを開発しています。基本的な構造は次のようになります。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/scrollview_settings"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="@dimen/paddingSmall">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent_white_settings"
android:paddingTop="@dimen/paddingMedium"
android:paddingBottom="@dimen/paddingMedium">
<ImageView
android:id="@+id/logo"
android:layout_width="68dp"
android:layout_height="wrap_content"
android:src="@drawable/newspaper_logo_color"
android:layout_alignParentRight="true"
android:layout_margin="@dimen/paddingBig"
android:adjustViewBounds="true"/>
</RelativeLayout>
<!-- Layout News Uebersicht -->
<include layout="@layout/separator_line_grey"/>
<de.basecom.noznewsapp.views.FontTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:textColor="@color/buttonHoverBackground"
android:textSize="@dimen/sliding_image_kicker_font_size"
android:paddingLeft="@dimen/paddingLarge"
android:paddingTop="@dimen/paddingMedium"
android:paddingBottom="@dimen/paddingMedium"
android:text="@string/news_overview"
android:textScaleX="@dimen/letter_spacing"
android:textStyle="bold"
android:gravity="center_vertical"
android:background="@color/settings_header_color"
android:layout_gravity="center_vertical"/>
<include layout="@layout/separator_line_grey"/>
<!-- News-Overview Issues -->
<LinearLayout
android:id="@+id/issue_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/transparent_white_settings">
<de.basecom.noznewsapp.views.NewsScrollListView
android:id="@+id/listview_issues"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:divider="@null"
android:dividerHeight="0dp" />
</LinearLayout>
<!-- Layout Einstellungen -->
<de.basecom.noznewsapp.views.FontTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:textColor="@color/buttonHoverBackground"
android:textSize="@dimen/sliding_image_kicker_font_size"
android:paddingLeft="@dimen/paddingLarge"
android:paddingTop="@dimen/paddingMedium"
android:paddingBottom="@dimen/paddingMedium"
android:text="@string/settings"
android:textStyle="bold"
android:textScaleX="@dimen/letter_spacing"
android:gravity="center_vertical"
android:background="@color/settings_header_color"
android:layout_gravity="center_vertical"/>
<include layout="@layout/separator_line_grey"/>
<!-- Einstellungs- Werte -->
<LinearLayout
android:id="@+id/settings_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/transparent_white_settings">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/paddingLarge">
<de.basecom.noznewsapp.views.FontTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/receive_pushmessages"
android:textAllCaps="true"
android:textScaleX="@dimen/letter_spacing"
android:textSize="@dimen/sliding_image_kicker_font_size"
android:layout_centerVertical="true"
android:textColor="@color/buttonBackground"/>
<Switch
android:id="@+id/receive_pushmessages_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="@string/empty_string"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
リストビューの場合、カスタム実装を使用して、高さを固定し、スクロールビュー内でスクロールできるようにしました(注:多くの要素があるため、スクロールビュー内でリストビューを使用する必要があり、線形レイアウトを使用するといいじゃない)。
public class CustomListView extends ListView {
public CustomListView(Context context) {
super(context);
}
public CustomListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomListView(Context context, AttributeSet attrs,int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// Calculate entire height by providing a very large height hint.
// But do not use the highest 2 bits of this integer; those are
// reserved for the MeasureSpec mode.
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
}
}
リストビューの各項目にはラベルとグリッドビューが含まれており、すべて正しく表示されています。しかし今、ユーザーがラベルをクリックしてグリッドビューの可視性を表示および非表示にできる機能を実装したいと考えています。
しかし、ラベルをクリックしてグリッドビューが表示されると、リストビューの高さが新しい開いている要素に適応しません。常に同じ高さにとどまり、要素を開くと、下の要素が表示されなくなります。requestLayout()
これは、リストビューのメソッドを呼び出して再度トリガーする場合にも発生onMeasure
します。
誰かが私が間違っていることを理解していますか?
編集:私のxmlファイルを更新しました:)