سؤال

I am doing an app that needs a fragment transaction, I made it, and it works, but the fragment doesn't stays inside the bounds of te frameLayout that is replacing, it fills all the activity.

Relevant code: MainActivity.java

public class MainActivity extends FragmentActivity 
{
@Override
    protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

CircleFragment myFragment = new CircleFragment();                                                                                                                       
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.frm_profile, myFragment).commit();
     }
 }

activity_main.xml

<FrameLayout
    android:id="@+id/frm_profile"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"                
    android:layout_alignParentTop="true"
    android:padding="5dp"
    android:background="@drawable/background_banner"      
 >     
    <RelativeLayout 
        android:id="@+id/rlt_profile"
        android:layout_width="match_parent"
        android:layout_marginTop="10dp"            
        android:layout_height="wrap_content">              
    <ImageView
        android:id="@+id/img_profile"
        android:layout_width="55dip"
        android:layout_height="55dip"
        android:contentDescription="@string/poi_poi_name"
        android:src="@drawable/logo_app_lrg" />    

    <TextView
        android:id="@+id/txt_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/img_profile"
        android:layout_toRightOf="@+id/img_profile"
        android:textColor="#040404"
        android:textSize="16sp"
        android:layout_marginLeft="10dp"
        android:text="Nombre"
        android:textStyle="bold"/>

    <TextView
        android:id="@+id/txt_status"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Status"
        android:layout_below="@+id/txt_name"
        android:layout_toRightOf="@+id/img_profile"
        android:textColor="#343434"
        android:layout_marginLeft="10dp"
        android:textSize="12sp" />    
     </RelativeLayout>     
</FrameLayout>    
 <com.google.android.gms.maps.MapView       
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_below="@+id/Rlt_address"                 
    android:id="@+id/map_locations" />

  <LinearLayout 
    android:id="@+id/lnr_buttons"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:padding="10dp"
    android:background="@drawable/background_banner"
    android:weightSum="3"
    android:orientation="horizontal">
    <ImageButton
        android:id="@+id/btn_call"
        android:src="@android:drawable/ic_menu_call"
        android:background="#00000000"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"                            
        android:layout_weight="1"/>

    <ImageButton
        android:id="@+id/btn_sms"
        android:src="@android:drawable/ic_menu_manage"
        android:background="#00000000"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"                                            
        android:layout_weight="1"/> 

     <ImageButton
        android:id="@+id/btn_refresh"
        android:background="#00000000"
        android:src="@android:drawable/ic_menu_compass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"                                                    
        android:layout_weight="1"/> 
    </LinearLayout>    

android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:background="#0b4d69"/>

CircleFragment.java

public class CircleFragment extends Fragment{

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
{
    return inflater.inflate(R.layout.list_element_circle, container,false);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) 
{

}
}

list_element_circle.xml

android:orientation="horizontal" android:background="#0b4d69" android:paddingTop="2dp">

<View 
   android:background="#FFFFFF" 
   android:layout_height="2dp" 
   android:layout_width="fill_parent"/>    
<TextView
    android:id="@+id/list_element_circle_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"        
    android:gravity="center_vertical"
    android:padding="5dp"                                                      
    android:text="Nombre"
    android:textColor="#FFFFFF"
    android:textSize="24sp"
    android:textStyle="bold"
    android:typeface="sans" />
<TextView
    android:id="@+id/list_element_circle_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"               
    android:padding="5dp"                                                      
    android:text=""
    android:textColor="#00000000"
    android:textSize="2sp"/>        
  <HorizontalScrollView 
    android:id="@+id/scrl_members"        
    android:layout_height="match_parent"
    android:scrollbars="none"
    android:paddingTop="40dp"
    android:paddingRight="5dp"
    android:paddingLeft="5dp"
    android:paddingBottom="10dp"
    android:layout_width="wrap_content">
    <LinearLayout 
        android:orientation="horizontal"
        android:layout_height="match_parent"
        android:layout_width="wrap_content">            
            <TextView
                android:id="@+id/list_element_circle_member1"
                android:drawableTop="@drawable/ic_action_person"
                android:drawablePadding="5dp"
                android:tag="list_element_circle_member1"
                android:textColor="#FFFFFF"
                android:layout_width="wrap_content"                 
                android:layout_height="match_parent"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="5dp"                    
                android:layout_gravity="center"                 
                android:text="Miembro"
                android:textSize="18sp" />
            <TextView
                android:id="@+id/list_element_circle_member2"
                android:drawableTop="@drawable/ic_action_person"
                android:tag="list_element_circle_member2"
                android:drawablePadding="5dp"
                android:textColor="#FFFFFF"
                android:layout_width="wrap_content"                 
                android:layout_height="match_parent"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"                    
                android:layout_gravity="center"                 
                android:text="Miembro"
                android:textSize="18sp"/> 
            <TextView
                android:id="@+id/list_element_circle_member3"
                android:drawableTop="@drawable/ic_action_person"
                android:tag="list_element_circle_member3"
                android:drawablePadding="5dp"
                android:textColor="#FFFFFF"
                android:layout_width="wrap_content"                 
                android:layout_height="match_parent"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"                    
                android:layout_gravity="center"                 
                android:text="Miembro"
                android:textSize="18sp"/> 
            <TextView
                android:id="@+id/list_element_circle_member4"
                android:drawableTop="@drawable/ic_action_person"
                android:tag="list_element_circle_member4"
                android:drawablePadding="5dp"
                android:textColor="#FFFFFF"
                android:layout_width="wrap_content"                 
                android:layout_height="match_parent"                    
                android:layout_gravity="center"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:text="Miembro"
                android:textSize="18sp" /> 
            <TextView
                android:id="@+id/list_element_circle_member5"
                android:drawableTop="@drawable/ic_action_person"
                android:tag="list_element_circle_member5"
                android:drawablePadding="5dp"
                android:textColor="#FFFFFF"
                android:layout_width="wrap_content"                 
                android:layout_height="match_parent"                    
                android:layout_gravity="center" 
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"                
                android:text="Miembro"
                android:textSize="18sp" />                                 
    </LinearLayout>        
 </HorizontalScrollView>        

What should I do, to make it stays in the frameLayout bounds?

MainActivity

هل كانت مفيدة؟

المحلول 2

I just re design the app, because I was trying for about 3 days and nothing seems to work. What I do is taking out the HorizontalScrollView. Keep the linearlayout horizontal and make the items inside the layout tinier so they fit.

This is definitely not a good answer, neither the one that I was looking for, but It's how I solved that problem.

نصائح أخرى

Your layout is very huge. The FrameLayout and the Fragment is working as expected, however since the content is too big it takes all the space.

Add a ScrollView on the outermost layout as below,

<ScrollView
   android:layout_width="match_parent"
   android:layout_height="match_parent" >
    <FrameLayout
       android:id="@+id/frm_profile"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"                
       android:layout_alignParentTop="true"
       android:padding="5dp"
       android:background="@drawable/background_banner">

     //your remaining main activity here    
</ScrollView>

and you will be able to scroll to see your rest of the layout. :)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top