0
我正在使用HorizontalScrollView
在屏幕上滑動TextViews
。我現在的問題是,如果有什麼方法可以使每個RelativeLayout
的寬度與電話屏幕的寬度相匹配,則與用戶使用的電話無關。如何設置視圖的寬度等於任何顯示?
那麼有沒有辦法像獲取設備的顯示寬度,然後將其設置爲我的RelativeLayout
的寬度?還是有更好的方法來做到這一點?
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:fillViewport="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="320dp"
android:layout_height="match_parent"
android:background="@android:color/holo_blue_dark">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="15sp"
android:textColor="@android:color/black"
android:id="@+id/info"
android:layout_margin="5dp"
android:textAlignment="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/info"
android:text="0"
android:textSize="80dp"
android:layout_centerHorizontal="true"
android:id="@+id/getrunkeneLiter"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="320dp"
android:layout_height="match_parent"
android:background="@android:color/holo_green_light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@android:color/black"
android:layout_margin="5dp"
android:id="@+id/danke"
android:textAlignment="center"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Feedback verfassen"
android:onClick="feedback"
android:layout_below="@+id/danke"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
</LinearLayout>
</HorizontalScrollView>
嘿嘿,謝謝!如何將relativeLayoutWidth設置爲Point的x值? .-。 – user7342339
我更新了示例以包含設置部分。 –
這只是天才!非常感謝您的幫助,謝謝! – user7342339