2016-07-28 6 views
1

私は画面の下半分を占めるScrollViewを持っています。 このScrollViewの内部には、多くのコンテンツを含むLinearLayout(垂直)を配置します。 アクティビティを開始すると、コンテンツが自動的にスクロールしてウィンドウの上部から開始されます。しかし、私はそれをScrollViewの上部(ウィンドウの中央)から始める必要があります。 私は何が間違っていますか?あなたは以下のように行うことができます enter image description hereScrollView内のLinearLayoutが下に自動スクロールされます

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="ru.intrigue.activities.EditActivity" 
    android:orientation="vertical"> 

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
     android:visibility="visible"> 

</RelativeLayout> 

<ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/scrollView2" 
     android:background="@color/colorDarkBack"> 

      <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:padding="10dp"> 


       <!-- content --> 

      </LinearLayout> 
    </ScrollView> 
</LinearLayout> 
+0

のベストは同様に – SMR

+0

あなたは 'ScrollViewを設定しているどのように関連するコードを投稿

your_scroll_view.post(new Runnable() { @Override public void run() { your_scroll_view.fullScroll(View.FOCUS_DOWN); } }); 

:いつオープンコードの下にあなたの活動コール

あなたの画面の半分を占有する? – SlashG

+0

あなたのXMLをここに入れてください –

答えて

0

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
android:weightSum="1"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.45" 
    android:orientation="vertical"> 

    <ImageView 
     android:id="@+id/frag_home_iv_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:adjustViewBounds="true" 
     android:scaleType="fitXY" 
     android:src="@drawable/demo" /> 

</LinearLayout> 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.55" 
    android:fadeScrollbars="false"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:weightSum="1"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="0.26" 
      android:gravity="center" 
      android:orientation="horizontal" 
      android:padding="@dimen/padding_5dp" 
      android:weightSum="1"> 

      <ImageView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.3" 
       android:src="@drawable/demo" /> 

      <TextView 
       android:id="@+id/fragment_home_tv" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.7" 
       android:paddingLeft="@dimen/padding_5dp" 
       android:text="@string/demo" 
       android:textColor="@color/BlackColor" /> 
     </LinearLayout> 
</LinearLayout> 


</ScrollView> 
</LinearLayout> 
0

あなたはlayout_weightプロパティを使用して所望の結果を達成することができます

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

     <!-- your content here--> 

    </LinearLayout> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <!-- your content here--> 

     </LinearLayout> 

    </ScrollView> 

</LinearLayout> 

が、それはあなたを助けている場合、私に教えてください。

+0

私はそれがしなかったのが怖いです。私はあなたが言ったように、今でも同じ行動をしていました。 –

+0

更新されたコードであなたの答えを[編集](http://stackoverflow.com/posts/38627466/edit) – SMR

1

あなたの問題のコードの下にすることによって解決する:運

関連する問題