1. ScrollView를 Root로 선언

2. Scrollview의 child의 LinearLayout의 height값을 wrap_content로  선언한다.

3. 앞의 LinearLayout의 child LinearLayout의 height값을 절대값은스크롤의 총 height값을 기재한다. 

   이 LinearLayout의 layout_weight값을 준다.(LinearLayout의 Root가 됨)


소스코드 예)


<ScrollView
android:id="@+id/scrollView1"
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:focusable="true"
android:orientation="vertical">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1200dip"
android:layout_weight="1"
android:background="@android:color/transparent"
android:focusable="false"
android:orientation="vertical"
android:visibility="visible"
android:weightSum="1">


Posted by MoGuWai 모과이IT
1. api의 결과를 담을 Model Class를 만든다(구조체와 비슷)
public class test1Model {
public String name;
public String addr;
public int discount;
public int distance;

public test1Model(String name, String addr, int discount, int distance) {
this.name = name;
this.addr = addr;
this.discount = discount;
this.distance = distance;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getAddr() {
return addr;
}

public void setAddr(String addr) {
this.addr = addr;
}

public int getDiscount() {
return discount;
}

public void setDiscount(int discount) {
this.discount = discount;
}

public int getDistance() {
return distance;
}

public void setDistance(int distance) {
this.distance = distance;
}
}
2. RetroBaseApiService 인터페이스 함수를에 등록한다.
@POST("/api/test1.php") Call<List<test1Model>> test1(@Query("dis1") int dis1,@Query("dis2") int dis2);
3. RetroClient 클래스에 실제 API를 구현한다.
public void test1(int dis1,int dis2, final RetroCallback callback) {
apiService.test1(dis1,dis2).enqueue(new Callback<List<test1Model>>() {
@Override
public void onResponse(Call<List<test1Model>> call, Response<List<test1Model>> response) {
if (response.isSuccessful()) {
callback.o


Posted by MoGuWai 모과이IT

Android does not provide a mechanism for using a custom font file (TTF, OTF, etc) in all areas of your app. Instead you must employ a strategy to set a custom Typeface on all TextViews, EditTexts, and Buttons.

This post covers a strategy that should handle your needs for common apps.

The View Crawler

Layouts (and sub-layouts) in Android are tree hierarchies comprised of ViewGroups as composite elements and Views as leaf nodes. This tree can be crawled by visiting child views in your favorite order (breadth first or depth first). When crawling this tree, one can replace all the Typefaces on any TextViews, EditTexts, and Buttons that are encountered.

Here is a simple recursive implementation of a view crawler that will replace the Typeface for any appropriate view in the hierarchy:

public class FontChangeCrawler
{
    private Typeface typeface;

    public FontChangeCrawler(Typeface typeface)
    {
        this.typeface = typeface;
    }

    public FontChangeCrawler(AssetManager assets, String assetsFontFileName)
    {
        typeface = Typeface.createFromAsset(assets, assetsFontFileName);
    }

    public void replaceFonts(ViewGroup viewTree)
    {
        View child;
        for(int i = 0; i < viewTree.getChildCount(); ++i)
        {
            child = viewTree.getChildAt(i);
            if(child instanceof ViewGroup)
            {
                // recursive call
                replaceFonts((ViewGroup)child);
            }
            else if(child instanceof TextView)
            {
                // base case
                ((TextView) child).setTypeface(typeface);
            }
        }
    }
}

Replace Entire Activity's Typeface

To replace the default font in every view within an Activity's layout, simply use the FontChangeCrawlerfrom above, like so:

@Override
public void setContentView(View view)
{
    super.setContentView(view);

    FontChangeCrawler fontChanger = new FontChangeCrawler(getAssets(), "font.otf");
    fontChanger.replaceFonts((ViewGroup)this.findViewById(android.R.id.content));
}

If you are not familiar with android.R.id.content, it is the official ID given to the root View within an Activity's layout.

Consider placing the above logic in a BaseActivity class.

Replace Fragment's Typeface

You will need to apply the FontChangeCrawler to each Fragment as well. Consider placing this logic in a BaseFragment class.

@Override
public void onActivityCreated(Bundle savedInstanceState)
{
    super.onActivityCreated(savedInstanceState);

    FontChangeCrawler fontChanger = new FontChangeCrawler(getAssets(), "font.otf");
    fontChanger.replaceFonts((ViewGroup) this.getView());
}

Handle Adapters, etc.

Replacing Activity fonts goes a long way, but most of us also have a plethora of ListViews. The list items in a ListView are built within an adapter, not within an Activity. Therefore, you will also need to use the FontChangeCrawler in your adapters:

...
if(convertView == null)
{
    convertView = inflater.inflate(R.layout.listitem, null);
    fontChanger.replaceFonts((ViewGroup)convertView);
}
...

What's Not Handled?

I will leave handling the ActionBar as an exercise for the reader. Also, consider how you might handle widgets whose typeface you don't want to change.



[출처]

https://coderwall.com/p/qxxmaa/android-use-a-custom-font-everywhere


Posted by MoGuWai 모과이IT