Ric*_*ral 24 user-interface android margin padding android-layout
我需要有一个LinearLayout内部SrollView,并且LinearLayout必须有一个边距ScrollView.首先,我能想到解决这个问题的唯一方法是LinearLayout在另一个内部LinearLayout设置最后一个布局设置的边距.如果将它们放在外面,它们将无法工作LinearLayout.
例:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:fillViewport="true"
android:background="@color/layout_color_green">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/layout_color_yellow">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical"
android:background="@color/layout_color_blue">
</LinearLayout>
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

我的问题是:为什么我需要这样做?
如果我只有一个LinearLayout就没有利润......
例:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:fillViewport="true"
android:background="@color/layout_color_green">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical"
android:background="@color/layout_color_blue">
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

然后,搜索一些类似的问题,我发现了一些布局,这让我想到了使用填充ScrollView代替边距LinearLayout.这也解决了我的问题,我不需要LinearLayout另一个内部.这是一个更优雅的解决方案.
不过,我想了解为什么内部的简单边距在内部时LinearLayout不起作用ScrollView.因为如果它不在里面它确实可以正常工作ScrollView.
谁知道为什么?
Kni*_*edi 16
我在源代码中挖了一点:
ScrollView延伸FrameLayout.这个本身有一些保证金问题,ScrollView甚至没有试图解决这个问题.在衡量时,边际基本上被忽略了.
但最终它并不重要,因为你应该能够在ScrollView自身上定义一个填充(这是一个肯定,没有尝试).单个子视图不应该有保证金.
him*_*009 11
你好Knickedi和Ricardo Amaral,
虽然这个答案标记为已解决,但我想对此问题进行一些阐述.
正如Knickedi所说,ScrollView扩展了FrameLayout.
所以我的答案是你可以layout_gravity在scrollView中设置LinearLayout,然后layout_margin在LinearLayout中使用LinearLayout中的LinearLayout.
我有同样的问题,我已经应用了这个,它对我有用.:)
示例:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginTop="30dp"
android:orientation="vertical" >
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17000 次 |
| 最近记录: |